zoukankan      html  css  js  c++  java
  • hdu 2391 Filthy Rich

    单纯dp 水一

    处理时间点,第一行和第一列特殊处理;

    其余的w[i][j]=show(w[i-1][j-1],w[i-1][j],w[i][j-1]);

    <span style="font-size:24px;"><span style="font-size:24px;">#include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<cmath>
    #include<iostream>
    using namespace std;
    int s[1005][1005];
    int w[1005][1005];//存每一个点的最大值
    int show(int q,int w,int e)
    {
        int t;
        if(q>w)
            t=q;
        else
            t=w;
        return t>e?t:e;
    }
    int main()
    {
        int a;
        scanf("%d",&a);
        int time=0;
        int b,c;
        int t=a;
        while(t--)
        {
            time++;
            scanf("%d %d",&b,&c);
            for(int i=0;i<b;i++)
                for(int j=0;j<c;j++)
                  scanf("%d",&s[i][j]);
            memset(w,0,sizeof(w));
            for(int i=0;i<b;i++)
                for(int j=0;j<c;j++)
                {
                    if(i==0)
                    {
                        if(j==0)
                           w[i][j]=s[i][j];
                        else
                            w[i][j]=w[i][j-1]+s[i][j];
                        continue;
                    }
                    if(j==0)
                    {
                        w[i][j]=w[i-1][j]+s[i][j];continue;
                    }
                    w[i][j]=show(w[i-1][j-1],w[i-1][j],w[i][j-1])+s[i][j];
                }
            printf("Scenario #%d:
    %d
    ",time,w[b-1][c-1]);
            //if(time!=a)
                printf("
    ");
        }
        return 0;
    }
    </span></span>


    版权声明:本文博主原创文章。博客,未经同意不得转载。

  • 相关阅读:
    希腊字母写法
    The ASP.NET MVC request processing line
    lambda aggregation
    UVA 10763 Foreign Exchange
    UVA 10624 Super Number
    UVA 10041 Vito's Family
    UVA 10340 All in All
    UVA 10026 Shoemaker's Problem
    HDU 3683 Gomoku
    UVA 11210 Chinese Mahjong
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4888258.html
Copyright © 2011-2022 走看看