POJ 3181 Dollar Dayz

100人阅读 评论(0)

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;
}

0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：46690次
• 积分：847
• 等级：
• 排名：千里之外
• 原创：28篇
• 转载：75篇
• 译文：0篇
• 评论：3条
文章分类
最新评论