UVA 10313 Pay the Price
来源:互联网 发布:达梦数据库6.0下载 编辑:程序博客网 时间:2024/05/17 20:52
算法:用前缀和把O(n^3)的dp优化成O(n^2)。注意:(1)long long。(2)L1、L2不一定在[1,300]内。(3)没有空行(不用处理空行能过)。
//10313 Pay the Price Accepted C++ 0.056 2012-11-20 11:23:14#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAXN = 300+5;const int MAX = 300;int N, L1, L2;long long d[MAXN][MAXN], f[MAXN][MAXN];char line[100];int main(){d[0][0] = f[0][0] = 1;for (int i = 1; i <= MAX; i++)for (int j = 1; j <= i; j++){d[i][j] = f[i-j][min(j, i-j)];f[i][j] = f[i][j-1]+d[i][j];}while (gets(line)){int n = sscanf(line, "%d%d%d", &N, &L1, &L2);if (n > 0){if (n == 1)printf("%lld\n", f[N][N]);else if (n == 2)printf("%lld\n", f[N][min(L1, N)]);else if (L1 > N)printf("0\n");else if (L1 > 0)printf("%lld\n", f[N][min(L2, N)]-f[N][L1-1]);elseprintf("%lld\n", f[N][min(L2, N)]);}}return 0;}
- uva 10313 Pay the Price
- UVA 10313 Pay the Price
- UVA 10313 Pay the Price
- uva 10313 - Pay the Price
- UVA - 10313 Pay the Price
- UVa:10313 Pay the Price
- uva 10313 - Pay the Price
- UVa 10313 - Pay the Price
- UVA - 10313 Pay the Price
- UVA - 10313 Pay the Price
- uva 10313 Pay the Price
- UVA 10313-Pay the Price(DP)
- uva 10313 Pay the Price (DP)
- Pay the Price+uva+dp
- 10313 - Pay the Price
- 10313 - Pay the Price
- 解题报告(一):uva 10313 - Pay the Price (dp)
- uva 10313 Pay the Price(完全背包)
- 纪念自己的第一个应用上线
- 频度和STL
- 正则相关
- 说女程序员&&女工程人员说脏话
- 管道过滤器的实现---java语言
- UVA 10313 Pay the Price
- 对费用流消负圈的小小理解
- ubuntu 10.10中安装openssh-server失败
- ubuntu下配置LAMP(Linux+Apache+Mysql+PHP)环境
- 打破设计惯例 注册时“暴露”密码更符合用户体验
- 求数组中最大子数组和(容器实现输入动态数组)
- 2013 训练计划
- 绑定控件中<%#Eval()%>和<%=变量%>的执行顺序
- WinForm把图片以二进制的方式存入到数据库,并将存入数据库的二进制图片读出显示到PictureBox中