CSU 1899: Yuelu Scenes
来源:互联网 发布:库里2016数据 编辑:程序博客网 时间:2024/05/29 09:29
题目:
Description
An artist begins with a roll of ribbon, one inch wide. She clips it into pieces of various integral lengths, then aligns them with the bottom of a frame, rising vertically in columns, to form a Yuelu scene. A Yuelu scene must be uneven; if all columns are the same height, it’s a plain scene, not a Yuelu scene! It is possible that she may not use all of the ribbon.
If our artist has 4 inches of ribbon and a 2 × 2 inch frame, she could form these scenes:
She would not form these scenes, because they're plains, not mountains!
Given the length of the ribbon and the width and height of the frame, all in inches, how many different Yuelu scenes can she create? Two scenes are different if the regions covered by ribbon are different. There’s no point in putting more than one piece of ribbon in any column.
Input
Each input will consist of several case. Each input will consist of a single line with three space-separated integers n, w and h, where n (0 n ≤ 10,000) is the length of the ribbon in inches, w (1 ≤ w ≤ 100) is the width and h (1 ≤ h ≤ 100) is the height of the frame, both in inches.
Output
Output a single integer, indicating the total number of Yuelu scenes our artist could possibly make, modulo 1e9 + 7.
Sample Input
25 5 515 5 510 10 14 2 2
Sample Output
7770605010226
题目意思是说,在宽w高h的矩形里面放格子,格子数量不超过n,问有多少种放法使得不是每一列都完全一样高。
其实只要求出所有的放法,再减去一样高的放法就可以了。
考虑在宽i(i从1到w)高h的矩形格子里面放j个格子有多少种方法,用ans[i][j]表示
那么ans[i][j]=ans[i][j-1]+ans[i-1][j]-ans[i-1][j-h]
数组越界的按0算,当然,编程要保证不会越界。
这样,ans[w][0]+ans[w][1]+......+ans[w][n]就是所有的放法,再减去一样高的放法就可以了。
用了动态规划的空间压缩(刷表),所以代码不太好看懂。
代码:
#include<iostream>using namespace std;int ans[10001],p=1000000007;int main(){int n,w,h;while(cin>>n>>w>>h){if(n>w*h)n=w*h;for(int i=0;i<=n;i++)ans[i]=(i<=h);for(int k=2;k<=w;k++){for(int i=k*h;i>=h+1;i--)ans[i]=(ans[i]-ans[i-h-1])%p;for(int i=1;i<=k*h;i++)ans[i]=(ans[i]+ans[i-1])%p;}int s=-1-n/w;for(int i=0;i<=n;i++)s=(s+ans[i])%p;cout<<(s%p+p)%p<<endl;}return 0;}
- CSU 1899: Yuelu Scenes
- 中南大学第十一届大学生程序设计竞赛-COJ1899-Yuelu Scenes
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- CSU
- mybatis原始dao开发实现用户的增删改查
- Juery实现隔行变色与传统js对比
- 对差分约束的理解
- AS添加第三方库的6种方式(Jar,module,so等)
- 【贪心】ZOJ
- CSU 1899: Yuelu Scenes
- 前端学HTTP之重定向和负载均衡
- 2017/4/24 阿里前端笔试题
- JSP中的taglib标签如何让JSP页面使用标签
- Linux命令行与shell脚本(3)--环境变量
- spring之属性注入
- //自己封装的几个函数方便记忆
- Android 接收无序广播
- POJ 3304 Segments(线段相交)