###### POJ 3181 Dollar Dayz

n=3+2
n=3+1+1
n=2+1+1+1
n=2+2+1
n=1+1+1+1+1

dp[i][j] 表示用i种价格配出金额j的方案数。

#include <iostream>
using namespace std;

unsigned long long b[105][1005], a[105][1005];
unsigned long long inf = 1;

int main()
{

int n, k;
cin >> n >> k;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; i < 18; ++i) {
inf *= 10;
}
a[0][0] = 1;
//dp[i][j] = dp[i – 1][j] + dp[i – 1][j – i] + dp[i – 1][j – 2 * i] + … + dp[i – 1][0]
for (int i = 1; i <= k; ++i)
{
for (int j = 0; j <= n; ++j)
{
for (int m = 0; m*i <= j; ++m)
{
b[i][j] = b[i][j] + b[i - 1][j - m*i] + (a[i][j] + a[i - 1][j - m*i]) / inf;
a[i][j] = (a[i][j] + a[i - 1][j - m*i]) % inf;
}
}
}

if (b[k][n]) {
cout << b[k][n];
}
cout << a[k][n] << endl;

return 0;
}

#include<iostream>

using namespace std;

long long a[105][1005], b[105][1005];

int main() {
int n, k;
cin >> n >> k;
long long inf = 1;
for (int i = 0; i < 18; ++i) {
inf *= 10;
}
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; i <= k; ++i) {
a[i][0] = 1;
}
//dp[i][j]=dp[i-1][j]+dp[i][j-i];
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= n; ++j) {
if (i > j) {
b[i][j] = b[i - 1][j];
a[i][j] = a[i - 1][j];
continue;
}
a[i][j] = (a[i - 1][j] + a[i][j - i]) % inf;
b[i][j] = b[i - 1][j] + b[i][j - i] + (a[i - 1][j] + a[i][j - i]) / inf;
}
}
if (b[k][n]) {
cout << b[k][n];
}
cout << a[k][n] << endl;
return 0;
}

#### POJ_3181 Dollar Dayz(dp,完全背包)

2015-09-18 17:29:40

#### poj3181 Dollar Dayz dp

2013-05-15 07:11:01

#### POJ3181：Dollar Dayz(完全背包)

2013-07-24 21:36:37

#### POJ 3181 Dollar Dayz 01完全背包问题

2014-08-29 11:13:47

#### Dollar Dayz POJ - 3181

2017-03-05 16:45:32

#### Poj 3181 Dollar Dayz

2012-10-08 08:57:19

#### bzoj1655 [Usaco2006 Jan] Dollar Dayz 奶牛商店(完全背包+高精)

2017-08-07 15:34:17

#### POJ 3181 Dollar Dayz （dp）

2015-03-07 02:06:04

#### poj 3181 P - Dollar Dayz

2017-10-07 11:04:38

## 不良信息举报

POJ 3181 Dollar Dayz