// For identifying Whether a subset exists or not
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
int finde(vector<int>answer,int sum)
{
int dp[answer.size()+1][sum+1];
for (int c(0);c<=sum;c++)dp[0][c]=0;
for (int c(1);c<=answer.size();c++){
for (int c1(0);c1<=sum;c1++){
if (answer[c]>c1)dp[c][c1]=dp[c-1][c1]; else dp[c][c1]=max(dp[c-1][c1],answer[c]+dp[c-1][c1- answer[c]]);
}
}
if (dp[answer.size()][sum]==sum)return 1; else return 0;
}
int main ()
{
int t;
scanf("%d",&t);
for (int c5(0);c5<t;c5++){
int n,sum;
vector<int>answer;
answer.push_back(0);
scanf("%d%d",&n,&sum);
for (int c(0);c<n;c++){int a;scanf("%d",&a);answer.push_back(a);}
if (finde(answer,sum))cout << "Yes" << endl; else cout << "No" << endl;
}
return 0;
}
I know its quite tedious to examine the code however i am in need of immense help .So can any one just point out the mistake in the above problem.The problem is http://www.codechef.com/problems/A1/
Thanx