• 冰水挑战(简单dp)


    冰水挑战

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2397    Accepted Submission(s): 429


     

    Problem Description

    Polar Bear Pitching helps you crystallize your message. 
    The stage could not be any cooler, and we mean literally: 
    a hole cut through the ice in the frozen Baltic Sea.

    2050有一项很有挑战的活动 —— Polar Bear Pitching 。
    体验人跳入冰水中讲述自己的恐惧,改变以及梦想。这是没有时间限制的演讲,就看你能在冰水中呆多久!

    现在,我们要依次面对 n 个冰水挑战,每个挑战你都可以选择接受或不接受。接受第 i 个挑战会让你丧失 ai点体力,因为每个挑战所处的环境不同,如果你要挑战它,在挑战它之前你的体力 x 会变成 min(x,bi),当你完成这个挑战的时候,你的体力会变成 x−ai,体力任何时候不允许小于等于 0,无论你是否接受第 i 个挑战,在这个挑战结束以后你的体力都会增加 ci。

    现在我们想知道最多可以完成多少个挑战。

     

    Input

    第一行一个正整数 T (T≤50) 表示数据组数。

    接下来 T 组数据,每组第一行两个正整数 n,c (1≤n≤103,1≤c≤109),表示挑战的数量和初始体力,接下来 n 行,每行三个非负整数 ai,bi,ci(0≤ai,bi,ci≤109)。

     

    Output

    对于每组数据输出一行一个数,表示你最多能完成几个挑战。

     

    Sample Input

    
     

    2 3 10 1 2 0 4 8 3 6 10 1 2 1 1 1 1 1 1 1

     

    Sample Output

    
     

    2 0

     

    Source

    
     

    Test Contest

    状态转移方程很容易推出来

    只是有些细节处理会导致wa

    #include <cstdio>
    #include <cmath>
    #include <cstdlib>
    #include <cstring>
    #include <ctime>
    #include <map>
    #include <set>
    #include <string>
    #include <queue>
    #include <stack>
    #include <algorithm>
    #include <iostream>
    using namespace std;
    long long dp[1005];
    long long a[1005];
    long long b[1005];
    long long c[1005];
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            long long n,d;
            scanf("%lld%lld",&n,&d);
            for(int i=1;i<=n;i++)
            {
                scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
            }
            memset(dp,0,sizeof(dp));
            dp[0]=d;
            for(int i=1;i<=n;i++)//nlun
            {
                for(int j=i;j>=1;j--)
                {
                    if(dp[j-1]!=0)
                    dp[j]=max(dp[j],min(dp[j-1],b[i])-a[i]);
                }
                for(int j=0;j<=i;j++)
                {
                    //cout<<dp[j]<<" ";
                    if(dp[j]!=0)
                    dp[j]+=c[i];
                }
                //cout<<endl;
            }
            int MAX=0;
            for(int i=0;i<=n;i++)
            {
                //cout<<i<<" "<<dp[i]<<endl;
                if(dp[i]) MAX=i;
            }
            printf("%d
    ",MAX);
        }
    }
  • 相关阅读:
    前端 JavaScript&Dom
    前端 css续
    前端 初级篇(CSS)
    前端 初级篇(HTML)
    堡垒机
    Python操作RabbitMQ
    常用到代码片段
    关于文件上传功能的思考
    JS正则表达式将url转成json格式
    一行代码解决各种IE兼容问题,IE6,IE7,IE8,IE9,IE10
  • 原文地址:https://www.cnblogs.com/caowenbo/p/11852291.html
Copyright © 2020-2023  润新知