Fruit
2015-08-07 10:21
337 查看
Fruit
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3907 Accepted Submission(s): 2223
[align=left]Problem Description[/align]
转眼到了收获的季节,由于有TT的专业指导,Lele获得了大丰收。特别是水果,Lele一共种了N种水果,有苹果,梨子,香蕉,西瓜……不但味道好吃,样子更是好看。
于是,很多人们慕名而来,找Lele买水果。
甚至连大名鼎鼎的HDU ACM总教头 lcy 也来了。lcy抛出一打百元大钞,"我要买由M个水果组成的水果拼盘,不过我有个小小的要求,对于每种水果,个数上我有限制,既不能少于某个特定值,也不能大于某个特定值。而且我不要两份一样的拼盘。你随意搭配,你能组出多少种不同的方案,我就买多少份!"
现在就请你帮帮Lele,帮他算一算到底能够卖出多少份水果拼盘给lcy了。
注意,水果是以个为基本单位,不能够再分。对于两种方案,如果各种水果的数目都相同,则认为这两种方案是相同的。
最终Lele拿了这笔钱,又可以继续他的学业了~
[align=left]Input[/align]
本题目包含多组测试,请处理到文件结束(EOF)。
每组测试第一行包括两个正整数N和M(含义见题目描述,0<N,M<=100)
接下来有N行水果的信息,每行两个整数A,B(0<=A<=B<=100),表示至少要买该水果A个,至多只能买该水果B个。
[align=left]Output[/align]
对于每组测试,在一行里输出总共能够卖的方案数。
题目数据保证这个答案小于10^9
[align=left]Sample Input[/align]
2 3 1 2 1 2 3 5 0 3 0 3 0 3
[align=left]Sample Output[/align]
2 12
[align=left]Author[/align]
Linle
[align=left]Source[/align]
ACM程序设计期末考试——2008-01-02(3
教417)
参考网址:http://www.acmerblog.com/hdu-2152-fruit-3301.html
my code:
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; int main() { int N,M,A[101],B[101],i,j,k,c1[101],c2[101]; while(scanf("%d%d",&N,&M)!=EOF) {memset(c1,0,sizeof(c1)); memset(c2,0,sizeof(c2)); for(i=0;i<N;i++) { cin>>A[i]>>B[i]; } for(i=A[0];i<=B[0];i++) c1[i]=1; for(i=2;i<=N;i++) { for(j=0;j<=M;j++) { for(k=A[i-1];k+j<=M&&k<=B[i-1];k++) c2[k+j]+=c1[j]; } for(k=0;k<=M;k++) { c1[k]=c2[k]; c2[k]=0; } } cout<<c1[M]<<endl; } return 0; }
大神的代码
#include <iostream> using namespace std; #define maxn 105 int a[maxn],b[maxn],minum[maxn],maxnum[maxn]; int main() { int n,m; while(cin>>n>>m) { for(int i = 0; i < n; i++) { cin>>minum[i]>>maxnum[i]; } memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(int i = minum[0]; i <= maxnum[0]; i++) a[i] = 1; for(int i = 1; i < n; i++) { for(int j = 0; j <= m; j++) { for(int k = minum[i]; k + j<=m && k <= maxnum[i];k++) { b[j+k] += a[j]; } } for(int j = 0; j <= m; j++) { a[j] = b[j]; b[j] = 0; } } cout<<a[m]<<endl; } }
相关文章推荐
- editui刷新数据与列表循环
- easyui阻止事件冒泡
- amazeui 懒加载 搜索不到图片时,如何为图片加上默认图
- 23. PHP include and require 文件
- EQueue性能测试计划
- NGUI 九宫格纹理拉伸
- Bluetooth Keyboard Replace
- Handler、Looper、MessageQueue(三)
- 哈希-4 Values whose Sum is 0
- 哈希-4 Values whose Sum is 0 分类: POJ 哈希 2015-08-07 09:51 3人阅读 评论(0) 收藏
- leetcode_Implement Stack using Queues
- UITextView实现placeholder的猥琐做法
- qt中的ui改变了,但是程序exe没有反应出来
- iOS UISegmentedControl 学习
- Poj 2299 Ultra-QuickSort (归排求逆序数)
- leetcode_Implement Queue using Stacks
- 基于mysql的程序抛异常 Unable to find the requested .Net Framework Data Provider. It may not be installed
- Android API Guides – Introduction to Android
- bluetooth发展(五岁以下儿童)------蓝牙功能测试(一个)
- iOS UI07_界面传值