HDU 2152

生成函数简单题

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 110
using namespace std;

struct Fruit{
	int a,b;
};
Fruit num[N];
int c1[N],c2[N];

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF){
		for(int i=1;i<=n;i++)
		scanf("%d%d",&num[i].a,&num[i].b);
		memset(c1,0,sizeof(c1));
		memset(c2,0,sizeof(c2));
		for(int i=num[1].a;i<=num[1].b;i++)
		c1[i]=1;
		for(int i=2;i<=n;i++){
			for(int j=0;j<N;j++){
				for(int k=num[i].a;k<=num[i].b&&k+j<N;k++)
				c2[k+j]+=c1[j];
			}
			for(int j=0;j<N;j++)
			c1[j]=c2[j],c2[j]=0;
		}
		printf("%d\n",c1[m]);
	}
	return 0;
}

  

时间: 2024-08-26 15:59:27

HDU 2152的相关文章

HDU 2152 Fruit( DP )

Fruit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3514    Accepted Submission(s): 1998 Problem Description 转眼到了收获的季节,由于有TT的专业指导,Lele获得了大丰收.特别是水果,Lele一共种了N种水果,有苹果,梨子,香蕉,西瓜……不但味道好吃,样子更是好看. 于是,

HDU 2152 Fruit

Fruit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3583    Accepted Submission(s): 2043 Problem Description 转眼到了收获的季节,由于有TT的专业指导,Lele获得了大丰收.特别是水果,Lele一共种了N种水果,有苹果,梨子,香蕉,西瓜--不但味道好吃,样子更是好看. 于是

HDU 2152 Fruit (母函数)

# include<stdio.h> # include <algorithm> # include <string.h> # include <iostream> using namespace std; int main() { int n,m,i,j,k; int c1[110],c2[110]; int a[110],b[110]; while(~scanf("%d%d",&n,&m)) { for(i=0;i&l

菜鸟授徒系列之母函数

这是第二次接触母函数类问题,相比于第一次的朦朦胧胧,第二次更加深刻.深深地感到母函数的强大,真是解决组合问题的一大法宝,将做过的题分类.总结加深一下记忆. 母函数包括:  普通生成函数(解决组合问题) 指数生成函数(解决排列问题) 这里全部是普通生成函数,可解决一系列组合问题,做题时要将题意与生成函数 G(x) = (1+x^2+x^3+x^4....) (1+x^2+x^4+....) (1+x^3+x^6+.....)······.相结合. 母函数模板包括三重循环:第一重指除第一个括号外的括

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

HDU 1085 Holding Bin-Laden Captive!

Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU——PKU题目分类

HDU 模拟题, 枚举1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201

HDU 1709 母函数天平问题 可出现减法的情况 The Balance

The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6652    Accepted Submission(s): 2730 Problem Description Now you are asked to measure a dose of medicine with a balance and a number o