hust 1422 Candy!

题目描述

Halloween
is coming! So xiaoY has to prepare M candies to treat the neighbor
kids.

When
this horrible night come, There are N little children ask xiaoY for candy, and
each of them has different demand. For the i-th kid, his (or her) candy must not
less than Min[i], and not greater than Max[i].

Now
xiaoY wants to know how many ways he can give out all of his candies. (in case
the large answer, please tell xiaoY the answer modular
10000007)

输入

First
line is an integer T, represents T cases followed:

N,
M ---- Number of children, Number of candies.

(0<N<=20,
0<M<=10000)

Min[i],
Max[i] ---- The lower bound and upper bound of I-th kid’s demand. (N
lines)

(0<=Min[i]
<= Max[i] <=M)

输出

Output
a number W which means total different ways of handing out the candies. (%
10000007)

样例输入

2
3 5
1 2
1 2
1 2
3 6
1 2
1 2
1 2

样例输出

Case #1: 3
Case #2: 1

神一样的题目,当然是dp解决了,dp[i+j]+=dp[j],表示将i放在当前的人,j给i前面的人,很好理解吧!我9000多ms过的,当然还有16ms过的,膜拜


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=10000+10;
const int mod=10000007;

int f1[maxn],f2[maxn];

int main()
{
int t,n,m,a,b,MAX;
scanf("%d",&t);
for (int tt=1;tt<=t;tt++)
{
memset(f1,0,sizeof(f1));
memset(f2,0,sizeof(f2));
scanf("%d%d",&n,&m);
scanf("%d%d",&a,&b);
for (int i=a;i<=b;i++) f1[i]=1;
MAX=b;
for (int k=2;k<=n;k++)
{
scanf("%d%d",&a,&b);
for (int i=0;i<=MAX && i<=m;i++)
{
for (int j=a;i+j<=m && j<=b;j++)
{
f2[i+j]+=f1[i];
f2[i+j]=f2[i+j]%mod;
}
}
MAX+=b;
for (int i=0;i<=MAX && i<=m;i++)
{
f1[i]=f2[i];
f2[i]=0;
}
}
printf("Case #%d: %d\n",tt,f1[m]%mod);
}
return 0;
}

hust 1422 Candy!,布布扣,bubuko.com

时间: 2024-10-17 12:53:28

hust 1422 Candy!的相关文章

HUST 1588 辗转数对

1588 - 辗转数对 时间限制:1秒 内存限制:128兆 155 次提交 27 次通过 题目描述 假设当前有一个数对(a, b),我们可以通过一步将这个数对变为一个新数对(a + b, b)或者是(a, a + b).初始的数对为(1, 1),你的任务是找到一个数字k,即通过最少的步数使得这个数对中至少一个数字等于n. 输入 输入包括多组数据,每组数据包括一行,每行有一个整数n. 输出 每组数据输出一行,每行一个整数n. 样例输入 5 3 样例输出 3 2 提示 第一个样例的方法是 (1,1)

HUST 1698 - 电影院 组合数学 + 分类思想

http://acm.hust.edu.cn/problem/show/1698 题目就是要把一个数n分成4段,其中中间两段一定要是奇数. 问有多少种情况. 分类, 奇数 + 奇数 + 奇数 + 奇数 奇数 + 奇数 + 奇数 + 偶数 偶数 + 奇数 + 奇数 + 奇数 偶数 + 奇数 + 奇数 + 偶数 然后奇数表达成 2 * a - 1这个样子,就能列出方程. 然后就是类似于解a1 + a2 + a3 + a4 = x的问题了. #include <cstdio> #include &l

[LeetCode][Java] Candy

题目: There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more cand

HUST 1017 - Exact cover (Dancing Links 模板题)

1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find o

勇士出征[HUST 1439]

勇士出征[HUST 1439] 时间1000ms,内存64MB 第十届"北大青鸟"杯浙江师范大学程序设计竞赛 这道题跟UVA-12100是一样的题目.我这里用的是STL的双端队列deque容器配合优先队列priority_queue,写起来会比较轻松:依次将输入压入队列,然后不断扫描队列,符合最大优先级的(优先队列的顶部元素)将其送出,而不再压入队尾.直到找到符合自己的标记的为止. 当然这道题也有用数组使用滚雪球的方式实现的,也就是开一个大的数组,每次将元素后挪时,直接将其放在数组末尾

从视频文件中读入数据--&gt;将数据转换为灰度图--&gt;对图像做candy边缘检测

//从视频文件中读入数据-->将数据转换为灰度图-->对图像做candy边缘检测 //作者:sandy //时间:2015-10-10 #include <cv.h> #include <highgui.h> int main(int argc, char *argv[]){ //预备工作 CvCapture* capture=cvCreateFileCapture("E:\\Videos\\xx.avi");//让capture变量指向视频文件 i

UVALive 2659+HUST 1017+ZOJ 3209 (DLX

UVALive 2659 题目:16*16的数独.试了一发大白模板. /* * @author: Cwind */ //#pragma comment(linker, "/STACK:102400000,102400000") #include <iostream> #include <map> #include <algorithm> #include <cstdio> #include <cstring> #include

HUST 1341 A - A Simple Task(哈理工 亚洲区选拔赛练习赛)

A - A Simple Task Time Limit:1000MS    Memory Limit:131072KB    64bit IO Format:%lld & %llu SubmitStatusPracticeHUST 1341 Description As is known to all, lots of birds are living in HUST. A bird has s units of food on the first day, and eats k units

[leet code 135]candy

1 题目 There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more can