标签:
Description
1 @ US$3 + 1 @ US$2
1 @ US$3 + 2 @ US$1
1 @ US$2 + 3 @ US$1
2 @ US$2 + 1 @ US$1
5 @ US$1
Write 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).Input
Output
Sample Input
5 3
Sample Output
5
#include <iostream> #include <queue> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <stack> #include <vector> #include <algorithm> using namespace std; #define N 2100 #define met(a,b) (memset(a,b,sizeof(a))) typedef long long LL; LL dp[N][2]; int main() { int n, m; while(scanf("%d%d", &n, &m)!=EOF) { int i, j; met(dp, 0); dp[0][0] = 1; for(i=1; i<=m; i++) for(j=i; j<=n; j++) { dp[j][0] += dp[j-i][0]; dp[j][1] += dp[j-i][1]; dp[j][1] += dp[j][0]/1000000000000000; dp[j][0] %= 1000000000000000; } if(dp[n][1]==0) printf("%I64d\n", dp[n][0]); else { printf("%I64d%015I64d\n", dp[n][1], dp[n][0]); } } return 0; }
参考http://www.cnblogs.com/kuangbin/archive/2012/09/20/2695165.html
(完全背包 大数)Dollar Dayz (POJ 3181)
标签:
原文地址:http://www.cnblogs.com/YY56/p/5537310.html