True love

Time Limit: 4000/2000 MS (Java/Others)     Memory Limit:128000/64000 KB (Java/Others)

Problem Description

Is there true love in the world?maybe or not, god knows! We know there are some complex relationships between ds and cxlove, they fell into love when they were rookies in acm,.

Now It's the season of graduation, it's also a season for lovers to say good-bye.But, ds and cxlove don't believe this. They want to show their true love and they plan to go out for a trip. But you know ds is a chihuo, he
has a lot of snacks, now he wants to know how many different volumes he can take with a bag of a certain capacity.

Input

First line there is a t. represent the test cases.

Each test case begins with two integers n, cap 

(1 <= n <= 100, 0 <= cap <= 100000).

the next line contains n integers denoting the volume of the snacks.

a[1], a[2], a[3]...a[n];

1 <= a[i] <= 100000

the last line contains n integers denoting the number of the corresponding snack.

b[1], b[2], b[3]...b[n];

1 <= b[i] <= 1000

Output

please look at the Sample Output

Sample Input

2
2 10
1 2
1 1 2 2
1 2
1 1

Sample Output

Case 1: 3
Case 2: 2

n*m背包。貌似第一次做这样的背包题。。。

。,思想还是非常easy懂的。

AC代码例如以下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int n,t,cap;
int i,j;
int a[105],b[105];
int dp[100005],times[100005];
int sum,cont=0;
scanf("%d",&t);
while(t--)
{
memset(dp,0,sizeof dp);
sum=0;cont++;
scanf("%d%d",&n,&cap);
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
for(i=1,dp[0]=1;i<=n;i++)
{
memset(times,0,sizeof times);
for(j=a[i];j<=cap;j++)
{
if(!dp[j]&&dp[j-a[i]]&&times[j-a[i]]<b[i])//枚举添加a[i]能在已有基础上到达的数值。
{
sum++;
times[j]=times[j-a[i]]+1;
dp[j]=1;
}
}
}
printf("Case %d: %d\n",cont,sum);
} return 0;
}

ACdream原创群赛(13)のwuyiqi退役专场 C True love的更多相关文章

  1. ACdream原创群赛(18)のAK's dream题解

    只做了4题水题ADGI A题需要注意的就是“[...]”的输出了,何时输出,何时不输出. #include <stdio.h> int main() { int n, cur, d; ; ...

  2. ACdream原创群赛__15

    这场感觉题目确实还算可以,不过,说好的每题10s效果上却不理想.这个时限还算比较紧.因为时间不是按绝对的多出几秒来计算,而是几倍来计算的. 比赛做的不好,后面又去做了一下. A:典型的数位DP,一直坑 ...

  3. dp --- acdream原创群赛(16) --- B - Apple

    <传送门> B - Apple Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...

  4. ACdream区域赛指导赛之专题赛系列(1)の数学专场

    Contest : ACdream区域赛指导赛之专题赛系列(1)の数学专场 A:EOF女神的相反数 题意:n(<=10^18)的数转化成2进制.翻转后(去掉前导零)输出十进制 思路:water ...

  5. “玲珑杯”线上赛 Round #17 河南专场

    闲来无事呆在寝室打打题,没有想到还有中奖这种操作,超开心的 玲珑杯”线上赛 Round #17 河南专场 Start Time:2017-06-24 12:00:00 End Time:2017-06 ...

  6. NOIP2017提高组 模拟赛13(总结)

    NOIP2017提高组 模拟赛13(总结) 第一题 函数 [题目描述] [输入格式] 三个整数. 1≤t<10^9+7,2≤l≤r≤5*10^6 [输出格式] 一个整数. [输出样例] 2 2 ...

  7. ACdream群赛1112(Alice and Bob)

    题意:http://acdream.info/problem?pid=1112 Problem Description Here  is Alice and Bob again ! Alice and ...

  8. 第六届acm省赛总结(退役贴)

    前言: 这是我的退役贴,之前发到了空间里,突然想到也要在博客里发一篇,虽然我很弱,但是要离开了还是有些感触,写出来和大家分享一下,希望不要见笑.回来看看,这里也好久没有更新了,这一年确实有些懈怠,解题 ...

  9. k8s升级,HA集群1.12.0~HA集群1.13.2

    k8s升级,此次升级是1.12.0 至1.13.2 准备 # 首先升级master节点的基础组件kubeadm.kubelet.kubectl apt policy kubeadm 找到相应的版本,如 ...

随机推荐

  1. python常用模块之sys, os, random

    一. sys模块 1. 作用: sys模块是与python解释器交互的一个接口 2. 具体使用 1. sys.argv 获取当前正在执行的命令行列表, 第一个为程序本身路径 print('file n ...

  2. Spring MVC 接入 rabbitMQ

    依赖包 <dependency> <groupId>org.springframework.amqp</groupId> <artifactId>spr ...

  3. my97datepicker插件日期值改变事件 等同于input的onchang()时间

    官网Demo地址http://www.my97.net/demo/index.htm <input type="text" class="Wdate" v ...

  4. 用cpp写对拍程序

    #include <bits/stdc++.h> using namespace std; int main() { while(true) { puts(""); p ...

  5. 图的最小生成树——Prim算法

    Prim算法 Prim算法求最小生成树是采取蓝白点的思想,白点代表已经加入最小生成树的点,蓝点表示未加入最小生成树的点. 进行n次循环,每次循环把一个蓝点变为白点,该蓝点应该是与白点相连的最小边权的是 ...

  6. 机器学习基础-Logistic回归2

    随机梯度上升法--一次仅用一个样本点来更新回归系数(因为可以在新样本到来时对分类器进行增量式更新,因而属于在线学习算法) 梯度上升法在每次更新回归系统时都需要遍历整个数据集,该方法在处理100个左右的 ...

  7. bzoj3142[Hnoi2013]数列 组合

    Description 小 T最近在学着买股票,他得到内部消息:F公司的股票将会疯涨.股票每天的价格已知是正整数,并且由于客观上的原因,最多只能为N.在疯涨的K天中小T观察 到:除第一天外每天的股价都 ...

  8. [NOIP2002] 提高组 洛谷P1031 均分纸牌

    题目描述 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,但纸牌总数必为 N 的倍数.可以在任一堆上取若于张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取的纸牌,只能移到编号为 2 ...

  9. BZOJ2060: [Usaco2010 Nov]Visiting Cows 拜访奶牛

    n<=50000个点的树,求选最多不相邻点的个数. f[i][0]=sigma max(f[j][0],f[j][1]),j为i的儿子 f[i][1]=sigma f[j][0],j同上 死于未 ...

  10. ArrayList去除重复元素

    去除一个ArrayList的重复元素有两种方法:(ArrayList与Vector的存储结构是Object[],LinkedList是双向列表) 第一种是不需要借助临时list,用equals方法比较 ...