int checkpar(int n ,int arr[], int sum , int csum,vector<vector>int dp){
if(dp[n][csum] ==-1){
if(n==0){
if(sum-csum==csum) return 1; else return 0; }
dp[n][csum]= checkpar(n-1,arr,sum ,csum,dp)+ checkpar(n-1,arr,sum,csum+arr[n-1],dp);
return dp[n][csum];
} else return dp[n][csum];
}
int equalPartition(int N, int arr[]) {
int sum=0;
for( int i=0;i<N;i++){ sum+=arr[i];
vector<vector<int>>dp(N+1,vector(sum+1,-1));
return checkpar(N,arr,sum,0,dp); }
RUNTIME ERROR
Attachments:
Answers
Answered by
2
Answer:
int checkpar(int n ,int arr[], int sum , int csum,vector<vector>int dp){
if(dp[n][csum] ==-1){
if(n==0){
if(sum-csum==csum) return 1; else return 0; }
dp[n][csum]= checkpar(n-1,arr,sum ,csum,dp)+ checkpar(n-1,arr,sum,csum+arr[n-1],dp);
return dp[n][csum];
} else return dp[n][csum];
}
int equalPartition(int N, int arr[]) {
int sum=0;
for( int i=0;i<N;i++){ sum+=arr[i];
vector<vector<int>>dp(N+1,vector(sum+1,-1));
return checkpar(N,arr,sum,0,dp); }
Answered by
0
Umm..Is it coding or anything else, what ?
Similar questions
English,
16 days ago
India Languages,
16 days ago
Geography,
1 month ago
Math,
1 month ago
Biology,
9 months ago