zoukankan      html  css  js  c++  java
  • HDU 1176 免费馅饼

    http://acm.hdu.edu.cn/showproblem.php?pid=1176


    中文题,问题很简单,就是求他最多能接到多少个馅饼

    这个题如果打出二维时间位置表很容易看出来和 杭电2084数塔  一样,都可以从最下面开始往上推,看总和最大。他能走的除了在0和10位置外都有3种选择。
    如下图括号里面的是和。  行代表时间t,列代表位置。

    注意:起点必须是从5开始(绿色区域),所以最终求的结果应该是这里的最大值。


    AC代码:
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    
    using namespace std;
    
    int dp[100010][11];
    
    int main()
    {
        int n,i,j,maxx,tim,x,t;
        while(scanf("%d",&n)&&n)
        {
            tim = 0;
            memset(dp,0,sizeof(dp));
            for(i = 0; i < n; i++)
            {
                scanf("%d%d",&x,&t);
                dp[t][x]++;
                if(t > tim)        //记录最大时间
                {
                    tim = t;
                }
            }
            maxx = 0;
            for(i = tim-1; i >= 0; i--)  //从倒数第二层开始求和
            {
                for(j = 0; j < 11; j++)
                {
                    if(j == 0)
                    {
                        dp[i][j] = max(dp[i][j]+dp[i+1][j],dp[i][j]+dp[i+1][j+1]);
    
                    }
                    else
                    {
                        if(j == 10)
                        {
                            dp[i][j] = max(dp[i][j]+dp[i+1][j],dp[i][j]+dp[i+1][j-1]);
                        }
                        else
                        {
                            dp[i][j] = max(max(dp[i][j]+dp[i+1][j],dp[i][j]+dp[i+1][j-1]),dp[i][j]+dp[i+1][j+1]);
                        }
                    }
                    if(dp[i][j] > maxx)
                    {
                        maxx = dp[i][j];
                    }
                }
            }
            printf("%d
    ",dp[0][5]);
        }
    
        return 0;
    }
    


  • 相关阅读:
    docker命令总结
    VulToEs
    MYSQL
    MoonStack
    Spring mvc json null
    MySQL
    极光推送
    坑爹的RockSaw和坑爹的windows7
    App接口设计思路
    CSUOJ 1329 一行盒子(数组模拟链表)
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3221522.html
Copyright © 2011-2022 走看看