LCT男人八题系列

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

1737Connected Graph1100LouTiancheng@POJ
1738An old Stone Game407LouTiancheng@POJ
1739Tony's Tour671LouTiancheng@POJ
1740A New Stone Game2240LouTiancheng@POJ
1741Tree1728LouTiancheng@POJ
1742Coins4309LouTiancheng@POJ
1743Musical Theme2687LouTiancheng@POJ
1744Elevator Stopping Plan469LouTiancheng@POJ

所谓男人八题就是以上八道了,我做的是最简单的一道,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;
}

 

转载于:https://www.cnblogs.com/Cw-trip/p/4464193.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值