CodeForces 687C The Values You Can Make
2016-07-07 10:34
316 查看
dp[i][j]表示i可以构成j则为true:
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <cmath> using namespace std; typedef long long LL; const int maxn = 1000 + 7; int n, k; bool dp[maxn][maxn]; int main() { scanf("%d%d", &n, &k); memset(dp, 0, sizeof(dp)); dp[0][0] = true; while(n--) { int t; scanf("%d", &t); for(int i = k; i >= 0; --i) { for(int j = 0; j <= k; ++j) { if(dp[i][j]) dp[i+t][j] = dp[i+t][j+t] = true; } } } int j = 0, a[maxn]; for(int i = 0; i <= k; ++i) if(dp[k][i]) a[j++] = i; printf("%d\n", j); for(int i = 0; i < j; ++i) { if(!i) printf("%d", a[i]); else printf(" %d", a[i]); } printf("\n"); }
相关文章推荐
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces 407C Codeforces Round #239 (Div. 1)C
- CodeForces 449A - Jzzhu and Chocolate
- CodeForces 449 B. Jzzhu and Cities
- codeforces 618C. Constellation
- Codeforces Round #349 (Div. 2) - C
- Codeforces Round #265 (Div. 2)
- Codeforces #310 div2 C. Case of Matryoshkas
- 状态压缩DP codeforces 244 Problem C. The Brand New Function 和 codeforces 165 E. Compatible Numbers
- codeforces 16 Problem E fish
- Codeforces Round332 部分题解
- CodeForces 603A_Alternative Thinking (DP)
- CodeForces 602B_Approximating a Constant Range_DP
- Codeforces round #247 for Div. 2
- Codeforces Round #246 (Div. 2)
- Codeforces #264(div 2)D.Gargari and Permutations
- Codeforces Round #236 (Div. 2)------A,B
- codeforces 257 div2 B