hdu 1398
```
People in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of all square numbers up to 289 (=17^2), i.e., 1-credit coins, 4-credit coins, 9-credit coins, ..., and 289-credit coins, are available in Silverland.
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.
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<string.h>
int from[301],to[301],n;
int main() {
while(scanf("%d",&n)&&n) {
memset(from,0,sizeof(from));
memset(to,0,sizeof(to));
from[0]=1;
for(int i=1;i*i<=n;i++) {
for(int j=0;j<=n;j+=i*i) {
for(int k=0;j+k<=n;k++) {
to[j+k]+=from[k];
}
}
memcpy(from,to,sizeof(to));
memset(to,0,sizeof(to));
}
printf("%d\n",from[n]);
}
}
hdu 1028
```
"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says.
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
"The second problem is, given an positive integer N, we define an equation like this:
N=a[1]+a[2]+a[3]+...+a[m];
a[i]>0,1<=m<=N;
My question is how many different equations you can find for a given N.
For example, assume N is 4, we can find:
4 = 4;
4 = 3 + 1;
4 = 2 + 2;
4 = 2 + 1 + 1;
4 = 1 + 1 + 1 + 1;
so the result is 5 when N is 4. Note that "4 = 3 + 1" and "4 = 1 + 3" is the same in this problem. Now, you do it!"
4 10 20
5 42 627```
#include<stdio.h>
#include<string.h>
#include<algorithm>
int from[121],to[121],n;
int main() {
while(scanf("%d",&n)!=EOF) {
memset(from,0,sizeof(from));
memset(to,0,sizeof(to));
from[0]=1;
for(int i=1;i<=n;i++) {
for(int j=0;j<=n;j+=i) {
for(int k=0;j+k<=n;k++) {
to[j+k]+=from[k];
}
}
memcpy(from,to,sizeof(to));
memset(to,0,sizeof(to));
}
printf("%d\n",from[n]);
}
}