Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //{ Driver Code Starts
- // Initial Template for C++
- #include <bits/stdc++.h>
- using namespace std;
- // } Driver Code Ends
- // User function Template for C++
- class Solution{
- public:
- vector<int> solve(int arr[],vector<int> &coins,int N)
- {
- if(N==0)
- {
- return coins;
- }
- int i,k;
- for(int i=0;i<=9;i++)
- {
- if(arr[i]>N)
- {
- k=arr[i-1];
- coins.push_back(k);
- break;
- }
- else if(i==9 && arr[i]<N)
- {
- k=arr[9];
- coins.push_back(k);
- break;
- }
- }
- return solve(arr,coins,N-k);
- }
- vector<int> minPartition(int N)
- {
- // code here
- int arr[]={ 1, 2, 5, 10, 20, 50, 100, 200, 500, 2000 };
- vector<int> coins;
- return solve(arr,coins,N);
- }
- };
- //{ Driver Code Starts.
- int main(){
- int t;
- cin>>t;
- while(t--){
- int N;
- cin>>N;
- Solution ob;
- vector<int> numbers = ob.minPartition(N);
- for(auto u: numbers)
- cout<<u<<" ";
- cout<<"\n";
- }
- return 0;
- }
- // } Driver Code Ends
Advertisement
Add Comment
Please, Sign In to add comment