fork download
  1. // dp[i][j][k] = number of ways to form a subset of sum i, using first j elements, and picking exactly k elements
  2. for(int i = 0; i <= 100; ++i) {
  3. dp[0][i][0] = 1;
  4. }
  5. for(int i = 1; i <= 10000; ++i) {
  6. for(int j = 0; j <= 100; ++j) {
  7. dp[i][0][j] = 0;
  8. }
  9. }
  10.  
  11. for(int sm = 1; sm <= 10000; ++sm) {
  12. for(int pos = 1; pos <= n; ++pos) {
  13. for(int used = 1; used <= n; ++used) {
  14. if(sm >= a[pos]) {
  15. dp[sm][pos][used] += dp[sm - a[pos]][pos - 1][used - 1];
  16. }
  17. dp[sm][pos][used] += dp[sm][pos - 1][used];
  18. }
  19. }
  20. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:2:1: error: expected unqualified-id before ‘for’
 for(int i = 0; i <= 100; ++i) {
 ^~~
prog.cpp:2:16: error: ‘i’ does not name a type
 for(int i = 0; i <= 100; ++i) {
                ^
prog.cpp:2:26: error: expected unqualified-id before ‘++’ token
 for(int i = 0; i <= 100; ++i) {
                          ^~
prog.cpp:5:1: error: expected unqualified-id before ‘for’
 for(int i = 1; i <= 10000; ++i) {
 ^~~
prog.cpp:5:16: error: ‘i’ does not name a type
 for(int i = 1; i <= 10000; ++i) {
                ^
prog.cpp:5:28: error: expected unqualified-id before ‘++’ token
 for(int i = 1; i <= 10000; ++i) {
                            ^~
stdout
Standard output is empty