Open LogicBaron opened 1 year ago
예시 코드)
class Solution {
public:
int numberOfWays(int n, int x) {
long long mod = 1e9+7;
vector<long long> dp(n+1, 0);
dp[0] = 1;
for (int i = 1; pow(i, x)<=n; i++) {
int ix = pow(i, x);
for (int j = n; j>=ix; j--) {
dp[j] = dp[j] + dp[j-ix];
dp[j] %= mod;
}
}
return dp[n];
}
};
Knapsack Problem List
Leetcode