We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Posting my solution using recursion if anyone is stuck.
#include<bits/stdc++.h>usingnamespacestd;#define MOD 1000000007typedeflonglongll;intmem[100001][8];lln,test;vector<int>ar;intrec(intvalue,intm){if(value==0)return1;if(value<0||m==ar.size())return0;int&ret=mem[value][m];if(ret!=-1)returnret;ret=rec(value-ar[m],m);ret=(ret+rec(value,m+1))%MOD;returnret;}intmain(){cin>>test;ar.push_back(1);ar.push_back(2);ar.push_back(5);ar.push_back(10);ar.push_back(20);ar.push_back(50);ar.push_back(100);ar.push_back(200);memset(mem,-1,sizeof(mem));while(test--){cin>>n;cout<<rec(n,0)<<endl;}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #31: Coin sums
You are viewing a single comment's thread. Return to all comments →
Posting my solution using recursion if anyone is stuck.