There are four combinations of coins to pay ten credits:
ten 1-credit coins,
one 4-credit coin and six 1-credit coins,
two 4-credit coins and two 1-credit coins, and
one 9-credit coin and one 1-credit coin.
Your mission is to count the number of ways to pay a given amount using coins of Silverland.
2 10 30 0
1 4 27
#include<stdio.h>
#include<iostream>
#define ll long long
using namespace std;
const int N=305;
ll s[N],a[N];
int read(){
int s=0;
char c=getchar();
while(c<'0'||c>'9'){
c=getchar();
}
while(c>='0'&&c<='9'){
s*=10;
s+=c-'0';
c=getchar();
}
return s;
}
void out(ll n){
if(n>9){
out(n/10);
}
putchar(n%10+'0');
}
int main(){
int i,j,k,n;
for(i=0;i<=N;i++){
s[i]=1;
a[i]=0;
}
for(i=2;i<=N;i++){
for(j=0;j<=N;j++){
for(k=0;j+k<=N;k+=i*i){
a[j+k]+=s[j];
}
}
for(j=0;j<=N;j++){
s[j]=a[j];
a[j]=0;
}
}
while(n=read()){
out(s[n]);
putchar('\n');
}
return 0;
}
7123



被折叠的 条评论
为什么被折叠?



