ACdream原创群赛(13)のwuyiqi退役专场 C True love

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;
}
时间: 2024-10-19 10:58:13

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

ACdream原创群赛(13)のwuyiqi退役专场 H Salmon And Cat

H 首先是要姿势正确! 注意完美数的生成机: 2+2a+2b+ab ab都是完美数 假设生成完美数c c = 2 + 2a + 2b + ab c + 2 = ab+2a+2b+4 c + 2 = (a + 2)(b + 2) 然后一开始只有两个完美数1和3. 所以所有的完美数只有质因数分解之后都是类似于 N = (3 ^ x) * (5 ^ y) 但是5不是完美数. 然后就没事了... /**** *COPYRIGHT NOTICE *Copyright (c) 2014 *All right

ACdream原创群赛(13)のwuyiqi退役专场 F The Arrow

F 首先是要理解概率求期望这种题目是用递归来解的! 大概规律就是: 完成事件A的期望是Ea,一次完成的概率是pa,那么 Ea = pa * Ea + (1 + Ea) * (1 - pa) 如果有好多种可能,比方说完成一个事件A的同时,也有诸如事件B的概率期望pb,Eb,事件C的概率期望pc,Ec等等等等,那么就分别写出来: Ea = pa * Ea + (1 + Ea) * (~pa) + pb * (1 + Eb) + pc * (1 + Ec) + ... 其中~pa是除了这些已知的事件发

ACdream原创群赛(18)のAK&#39;s dream题解

只做了4题水题ADGI A题需要注意的就是“[...]”的输出了,何时输出,何时不输出. 1 #include <stdio.h> 2 int main() 3 { 4 int n, cur, d; 5 int cnt = 1; 6 while(scanf("%d%d%d",&n,&cur,&d)!=EOF) 7 { 8 printf("Case #%d: ",cnt++); 9 if(cur==1) 10 printf(&quo

ACdream原创群赛__15

这场感觉题目确实还算可以,不过,说好的每题10s效果上却不理想.这个时限还算比较紧.因为时间不是按绝对的多出几秒来计算,而是几倍来计算的. 比赛做的不好,后面又去做了一下. A:典型的数位DP,一直坑在这里. E:求f(f(f(n)))%p.f()表示斐波那契数.关于求斐波那契数模的循环节是有特定的数学定理和方法的.我也不知道,但是看了结论之后自己会实现了.首先,把p因数分解,ai^pi,显然最终的循环节就等于这些单独因子计算循环节的lcm.同时ai^pi的循环节又是G(ai)*ai^(pi-1

ACdream原创群赛(18)のAK&#39;s dream

ACdream原创群赛(18)のAK's dream 题目链接 A:水题,直接模拟题意去搞即可 D:贪心+组合数学,把剑和英雄都从小到大排序,每次计算该英雄能用前几把剑cnt,cnt减去之前有多少人就是该英雄能选的,种数乘上cnt - 之前有多少人 F:DP,dp[i][j][2]表示第i天,用了j次修改,当前状态是A还是B,然后去转移即可 G:水题,直接用字符串处理即可,把数字都加上前导零方便判断 H:几何,利用正弦定理,余弦定理乱搞就可以了 I:水题,直接每个位置推出来输出,化简利用gcd即

acdream原创群赛(16) --- B - Apple

<传送门> B - Apple Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description Alice and Bob are coming.This time, they are playing with apples. Initially, there are N baskets and M apples. Both bas

ACdream原创群赛(16) F

MST Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description Given a connected, undirected graph, a spanning tree of that graph is a subgraph that is a tree and connects all the vertices togeth

ACdream原创群赛(16) J

Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitStatus Problem Description You are given an N*N digit matrix and you can get several horizontal or vertical digit strings from any position. For example: 123 4

ACdream原创群赛(11)の风神日华神专场 C.神奇的%系列一

3.算法综合实践——搜索引擎 上网搜索有关“搜索引擎”的相关资料,包括但不限于以下方面(至少要有2个方面):搜索引擎岗位要求.搜索引擎工作原理.搜索引 擎涉及到教材中哪些算法.搜索引擎的盈利模式.搜索引擎源码链接.国内外搜索引擎公司现状等. <1>搜索引擎指自动从因特网搜集信息,经过一定整理以后,提供给用户进行查询的系统.因特网上的信息浩瀚万千,而且毫无秩序,所有的信息像汪洋上的一个个小岛,网页链接是这些小岛之间纵横交错的桥梁,而搜索引擎,则为用户绘制一幅一目了然的信息地图,供用户随时查阅.