UVA_10313
After reading RoBa's question, I finally realized it.
This topic involves a conclusion that the number of solutions to generate I with no more than j coins is the same as the number of solutions to generate I with a coin with no more than j coins. A mathematical point is that integer I is split into split scores of up to j integers, which is the same as the split scores of integer I split into several integers whose values do not exceed j. The specific proof uses the Ferrers image nature.
In this way, we can take a two-dimensional array f [I] [j] to show the number of methods to use coins with a nominal value not greater than j to generate a nominal value I. If I use a nominal value j, f [I-j] [j] should be added to the number of corresponding solutions, if we do not use the face value j, then the corresponding number of solutions should be added with f [I] [J-1]. That is to say, the state transition equation is f [I] [j] = f [I-j] [j] + f [I] [J-1].
#include<stdio.h>
#include<string.h>
#define MAXN 310
char b[100];
int N, L1, L2;
long long int f[MAXN][MAXN];
void prepare()
{
int i, j;
N = 300;
memset(f, 0, sizeof(f));
f[0][0] = 1;
for(i = 0; i <= N; i ++)
for(j = 1; j <= N; j ++)
{
if(i - j >= 0)
f[i][j] += f[i - j][j];
if(j - 1 >= 0)
f[i][j] += f[i][j - 1];
}
}
void solve()
{
int i, j;
L1 = L2 = -1;
sscanf(b, "%d%d%d", &N, &L1, &L2);
L1 = L1 > 300 ? 300 : L1;
L2 = L2 > 300 ? 300 : L2;
if(L1 == -1)
printf("%lld\n", f[N][N]);
else
{
if(L2 == -1)
printf("%lld\n", f[N][L1]);
else
{
if(L1 == 0)
printf("%lld\n", f[N][L2]);
else
printf("%lld\n", f[N][L2] - f[N][L1 - 1]);
}
}
}
int main()
{
prepare();
while(gets(b) != NULL)
{
solve();
}
}