LCT男人八题系列

楼教的男人八题名气甚大,今天做了一道感觉还是涨了不少姿势的,然而估计之后的每道题都要看题解吧,姑且先记录一下。以后再做再更

1737 Connected Graph 1100 [email protected]
1738 An old Stone Game 407 [email protected]
1739 Tony‘s Tour 671 [email protected]
1740 A New Stone Game 2240 [email protected]
1741 Tree 1728 [email protected]
1742 Coins 4309 [email protected]
1743 Musical Theme 2687 [email protected]
1744 Elevator Stopping Plan 469 [email protected]

所谓男人八题就是以上八道了,我做的是最简单的一道,1742,dp,这题不把数组写成一维会mle,代码记录如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxv=1e5+30;
int n,m;
int dp[maxv];
int a[104],c[105];
int main(){
    //freopen("in","r",stdin);
    while(cin>>n>>m){
        if(n==0&&m==0) break;
        for(int i=1;i<=n;i++) scanf("%d",&a[i]);
        for(int i=1;i<=n;i++) scanf("%d",&c[i]);
        memset(dp,-1,sizeof dp);
        dp[0]=0;
        for(int i=1;i<=n;i++){
            for(int j=0;j<=m;j++){
                if(dp[j]>=0) dp[j]=c[i];
                else if(j-a[i]<0||dp[j-a[i]]<0) dp[j]=-1;
                else dp[j]=dp[j-a[i]]-1;
            }
        }
        int ans=0;
        for(int i=1;i<=m;i++){
            if(dp[i]>=0) ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
时间: 2024-12-23 14:06:13

LCT男人八题系列的相关文章

poj 1741 楼教主男人八题之一:树分治

http://poj.org/problem?id=1741 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an integer k,for every pair (u,v) of vertices is called valid

poj 1743 Musical Theme(男人八题&amp;后缀数组第一题)

Musical Theme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 17298   Accepted: 5939 Description A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the

POJ1742 Coins(男人八题之一)

前言 大名鼎鼎的男人八题,终于见识了... 题面 http://poj.org/problem?id=1742 分析 § 1 多重背包 这很显然是一个完全背包问题,考虑转移方程: DP[i][j]表示用前i种硬币能否取到金额j,ture表示可以,false表示不行. 则有 DP[i][j] = DP[i - 1][j] | DP[i - 1][j - k * Ai], 0 ≤ k ≤ Ci, j - k * Ai ≥ 0 这是一个O(N3)的算法,考虑到数据范围1 ≤ N ≤ 100, M ≤

男人八题2019

打的第三年男人八题了= = 感觉自己可能能创造一个EZ历史上打过最多男人八题的人(嘤嘤嘤我明明是妹子啊 考场上是5题 目前补了7题 目录 Biology Chemistry Chinese English Geography History Math Physics Biology 模拟= = //Love and Freedom. #include<cstdio> #include<algorithm> #include<cstring> #include<cm

POJ 1741 男人八题——树分治

Tree Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 23829   Accepted: 7900 Description Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dist(u,v)=The min distance between node u and v. Give an

poj1737~poj1744——ltc男人八题

准备开刷这充满神秘感的八道题,虽然我不是男的... 完成度:3/8 2016.7.~?   poj1742 Coins 题意:给你n种面值的硬币和每种硬币的数量.求1~m中有多少个可以用这些硬币组成. 算法:dp 解析:dp[i][j]表示用前i中硬币组成j时第i种硬币剩余的枚数(若不能组成j则为-1) 考虑以下四种情况: (1)若dp[i-1][j]>=0,则无需第i种硬币,为c[i] (2)若val[i]>j,面值太大,则为-1 (3)若dp[i][j-val[i]]<=0,无法组成

hdu 2844 Coins 多重背包模板题 ,二进制优化。据说是楼教主的男人八题之一

Coins Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 8052    Accepted Submission(s): 3291 Problem Description Whuacmers use coins.They have coins of value A1,A2,A3...An Silverland dollar. One

新男人八题---AStringGame

终于完成进度男人1/8,为了这题学了sam= = 题意先有一个串,n个子串,两个人轮流每次在子串上加字符,要求加完后还是原串的子串,最后不能加的就是输者,求赢的人 解法:sam之后在构造的状态图上跑sg函数,这题的sg状态不会超过26,所以直接枚举所有状态即可,然后记忆化搜索求sg函数,最后异或起来就是答案了 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-stack

男人八题_POJ-1741

题目链接:http://poj.org/problem?id=1741 树分治相关论文:http://wenku.baidu.com/view/60c6aa1ffc4ffe473368aba8.html 由于论文中有该题的讲解,所以便不再赘述.代码如下 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std;