Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void test(int arr[],int n)
- {
- int i,j;
- int maxx=0;
- int a[10][n+1];
- for(i=0;i<10;i++)
- {
- for(j=0;j<=n;j++)a[i][j]=0;
- }
- for(i=0;i<10;i++)
- {
- for(j=1;j<=n;j++)
- {
- if(i==0)a[i][j]=j;
- else{
- if(arr[i]>j)a[i][j]=a[i-1][j];
- else{
- a[i][j]=min(a[i-1][j],1+a[i][j-arr[i]]);
- }
- }
- }
- }
- i=9;
- j=n;
- while(j!=0)
- {
- if(i>0&&a[i-1][j]==a[i][j])i--;
- else{
- cout<<arr[i]<<" ";
- j-=arr[i];
- }
- }
- }
- int main()
- {
- int i,j,m,n,t;
- cin>>t;
- int arr[] ={1,2,5,10,20,50,100,200,500,2000};
- while(t--)
- {
- cin>>n;
- test(arr,n);
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement