标签:fine sig math day disco AC arc http sam
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8672 | Accepted: 3233 |
Description
1 @ US$3 + 1 @ US$2Write a program than will compute the number of ways FJ can spend N dollars (1 <= N <= 1000) at The Cow Store for tools on sale with a cost of $1..$K (1 <= K <= 100).
1 @ US$3 + 2 @ US$1
1 @ US$2 + 3 @ US$1
2 @ US$2 + 1 @ US$1
5 @ US$1
Input
Output
Sample Input
5 3
Sample Output
5
Source
#define _CRT_SECURE_NO_DEPRECATE #include<iostream> #include<algorithm> #include<cmath> #include<cstring> using namespace std; typedef unsigned long long ll; #define N_MAX 1000+20 #define K_MAX 100+20 #define MOD 100000000000000000 int n, k; ll dp[K_MAX][N_MAX][2]; int main() { scanf("%d%d",&n,&k); dp[0][0][1] = 1; for (int i = 1; i <= k;i++) { dp[i][0][1] = 1; for (int j = 1; j <= n;j++) { if (j >= i) { dp[i][j][0] = dp[i - 1][j][0] + dp[i][j - i][0]; dp[i][j][1] = dp[i - 1][j][1] + dp[i][j - i][1]; dp[i][j][0] += dp[i][j][1] / MOD; dp[i][j][1] %= MOD; } else { dp[i][j][0] = dp[i - 1][j][0]; dp[i][j][1] = dp[i - 1][j][1]; } } } if (dp[k][n][0]) { cout << dp[k][n][0]; } cout << dp[k][n][1]<<endl; return 0; }
标签:fine sig math day disco AC arc http sam
原文地址:https://www.cnblogs.com/ZefengYao/p/8992740.html