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.
- Prepare
- Mathematics
- Combinatorics
- Coinage
- Discussions
Coinage
Coinage
Sort by
recency
|
23 Discussions
|
Please Login in order to post a comment
5 line Python, 100%
Works for arbitrary number of coins with arbitrary values. Standard dp, use memoization or @cache python builtin.
Python small solution.
SHORTEST CODE TO THIS QUESTION
int min(int a, int b) {int c=a; if(a>b) c=b; return c; }
int main() { int t,n,a,b,c,d,i,j,k,l; scanf("%d",&t);
}
Solution for C++
The editorial optimization 3 is wrong and bad way . The optimization 4 is good approach . Suppose u have 0 1 coins , 3 2 coins ,2 5 coins , 1 10 coins. Then U can't make N if(13) But as rule of optimization of 3
(2*i+5*j+10*k>=(N-A)) count++;
many times 2*i+5*j+10*k this part will be greater than (13-0) . So what rubbish solution that is !!!
include
using namespace std;
int main() { int T,N,A,B,C,D; cin>>T; while(T--) { cin>>N; cin>>A>>B>>C>>D; long long ways[N+1]={0}; for(int i=0;i<=A;i++) { for(int j=0;j<=B&&(i+2*j)<=N;j++) { ways[(i+2*j)]++; } } long long ans=0; for(int i=0;i<=C&&(i*5)<=N;i++) { for(int j=0;j<=D&&((i*5)+(10*j))<=N;j++) { ans+=ways[N-((i*5)+(10*j))]; } } cout<