Skip to content

Instantly share code, notes, and snippets.

@KPCCoiL
Created November 5, 2014 09:21
Show Gist options
  • Save KPCCoiL/28628a2b09c0a6b780bb to your computer and use it in GitHub Desktop.
Save KPCCoiL/28628a2b09c0a6b780bb to your computer and use it in GitHub Desktop.
//Typical DP contest A
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin>>n;
vector<int> p(n);
for (auto& i : p) cin>>i;
vector<vector<bool>> dp(n+1, vector<bool>(10001, false));
dp[0][0] = true;
for (auto i = 0; i < n; i++)
for (auto j = 10000; j >= 0; j--)
if (dp[i][j]) dp[i+1][j] = dp[i+1][j+p[i]] = true;
int cnt = 0;
for (auto i = 0; i <= 10000; i++)
if (dp[n][i]) ++cnt;
cout << cnt << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment