Advertisement
Falak_Ahmed_Shakib

coins chng dppp

Feb 23rd, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. typedef pair<ll,ll>pll;
  6. typedef pair<ll,pair<ll,ll>>plll;
  7. #define bismillah; (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  8. #define vll(v) v.begin(),v.end()
  9. #define all(x) x.rbegin(),x.rend()
  10. #define min3(a, b, c) min(a, min(b, c))
  11. #define max3(a, b, c) max(a, max(b, c))
  12. #define in freopen("input.txt", "r", stdin)
  13. #define out freopen("output.txt", "w", stdout)
  14. #define minheap int,vector<int>,greater<int>
  15. #define pb push_back
  16. #define eb emplace_back
  17. const int Max = 2e5 ;
  18. const int Mod = 1e9 + 7;
  19. const int N=1e6;
  20. int main()
  21. {
  22.  
  23. ll n,c;
  24. cin>>n>>c;
  25.  
  26. ll coins[n+1];
  27. bool dp[n+1][c+1];
  28. memset(dp,0,sizeof(dp));
  29.  
  30. for(ll i=1;i<=n;i++) cin>>coins[i];
  31.  
  32. for(ll i=0;i<=n;i++) dp[i][0]=1;
  33.  
  34.  
  35.  
  36. for(ll i=1;i<=n;i++)
  37. {
  38. for(ll j=1;j<=c;j++)
  39. {
  40.  
  41. dp[i][j]=dp[i-1][j];
  42.  
  43. if(j-coins[i]>=0)dp[i][j]=(dp[i][j]|dp[i-1][j-coins[i]]);
  44.  
  45.  
  46. }
  47. }
  48.  
  49.  
  50. for(ll i=0;i<=c;i++)
  51. {
  52. cout<<i<<" "<<dp[n][i]<<endl;
  53. }
  54.  
  55.  
  56. if(dp[n][c])
  57. {
  58. cout<<"YES "<<endl;
  59.  
  60. ll i=n,j=c;
  61.  
  62. while(i and j)
  63. {
  64.  
  65. if(dp[i-1][j]==0)
  66. {
  67. cout<<coins[i]<<" ";
  68.  
  69. j-=coins[i];
  70.  
  71. }
  72.  
  73. i--;
  74.  
  75.  
  76. }
  77.  
  78. cout<<endl;
  79.  
  80.  
  81.  
  82.  
  83.  
  84. }
  85. else cout<<"NO"<<endl;
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement