题目来源
题目难度
3星
算法标签
完全背包 + 高等代数
参考程序
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 105, M = 25005;
int n;
int a[N];
//前i个货币构成金额j的方案数
int dp[2][M];
int main()
{
int T;
cin >> T;
while(T --)
{
//初始化
memset(dp, 0, sizeof dp);
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
}
sort(a+1, a+1+n);
int m = a[n];
int ans = 0;
//dp初始化
dp[0][0] = 1;
for(int i = 1; i <= n; i ++)
{
if(dp[(i-1)%2][a[i]] == 0)
{
ans ++;
}
for(int j = 0; j <= m; j ++)
{
//不选
dp[i%2][j] = dp[(i-1)%2][j];
if(j >= a[i])
{
dp[i%2][j] = dp[i%2][j] + dp[i%2][j-a[i]];
}
}
}
cout << ans << endl;
}
return 0;
}
标签:acwing532,int,系统,cin,货币,include,i%,dp
From: https://www.cnblogs.com/chaosliang/p/17237980.html