What is wrong in my code. In videos I replace only temp=dp[I]
.That is it.then what it is not running well.
What is wrong in my code?
sorry I get question wrong!!
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; int temp,arr[m],dp[n+1]={0}; // cout<<n<<" “<<m<<endl; // cin.get(); for(int i=0;i<m;i++){ cin>>arr[i]; } sort(arr,arr+m); bool iscoin=false; for(int i=1;i<=n;i++){ iscoin=false; temp=0; for(int j=0;j<m;j++){ if((i-arr[j])==0){ iscoin=true; break; } if((i-arr[j])>0 && dp[i-arr[j]]>0){ temp=temp+1+dp[i-arr[j]]; } } if(iscoin){ temp++; } dp[i]=temp; temp=0; } for(int i=0;i<=n;i++){ cout<<dp[i]<<” "; } // cout<<dp[n]; return 0; }
how to remove similar cases like 2,3 and 3,2.