UVA 10313 Pay the Price
2012-05-12 21:07
411 查看
其实这个题目可以用原来的换硬币的方法来解决,但是这个题目是也是一个这样的问题:求把一个整数i最多拆分成j个数时的方法数。
f[i][j]表示把一个整数i最多拆分成j个数时的方法数,f[0][0]=1;状态转移方程是f[i][j]=f[i-j][j]+f[i][j-1].
下面贴代码:
View Code
f[i][j]表示把一个整数i最多拆分成j个数时的方法数,f[0][0]=1;状态转移方程是f[i][j]=f[i-j][j]+f[i][j-1].
下面贴代码:
View Code
#include <stdio.h> #include <string.h> long long int f[301][301]; char s[100]; int main() { int a,b,c,i,j; memset(f,0,sizeof(f)); f[0][0] = 1; for(i = 0;i <= 300;i++) for(j = 1;j <= 300;j++) { f[i][j] = f[i][j - 1]; if(i >= j) f[i][j] += f[i - j][j]; } while(gets(s) != NULL) { switch(sscanf(s,"%d%d%d",&a,&b,&c)) { case 1: printf("%lld\n",f[a][a]); break; case 2: b = b > 300 ? 300 : b; printf("%lld\n",f[a][b]); break; default: b = b > 300 ? 300 : b; c = c > 300 ? 300 : c; if(b) printf("%lld\n",f[a][c] - f[a][b - 1]); else printf("%lld\n",f[a][c]); } } return 0; }
相关文章推荐
- uva 10313 Pay the Price(完全背包)
- uva 10313 - Pay the Price
- UVA 10313-Pay the Price(DP)
- UVa 10313 Pay the Price (DP&整数拆分)
- UVA 10313 Pay the Price
- 解题报告(一):uva 10313 - Pay the Price (dp)
- UVa 10313 - Pay the Price
- uva 10313 Pay the Price
- UVA - 10313 Pay the Price
- dp(整数拆分 uva10313 - Pay the Price)
- uva 10313 Pay the Price
- uva 10313 Pay the Price (DP)
- UVA 10313 Pay the Price(数字分解DP)
- UVa 10313 Pay the Price(类似数字分解DP)
- UVA10313- Pay the Price
- UVA - 10313 Pay the Price 整数的划分问题 01背包
- UVA 10313 Pay the Price
- uva 10313 - Pay the Price
- UVA - 10313Pay the Price(完全背包)
- uva 10313 Pay the Price(完全背包)