HDU 1176

這個題自己生想想出了狀態轉移方程。


結果邊界沒有處理好。 把邊界處理處理就A了


後來看了一下題解。 才知道是 《數塔》  數塔也就是 數字三角形。 如果知道是數塔這個狀態轉移方程明顯很好寫。。


我沒按照數塔的思路寫。 其實也差不多。 就是按照題意。 對於每一秒 他可能走到的每一個位置的最大值是多少。


這一秒 這一個位置肯定來自於 上一秒 上一個位置。然後就寫出來了


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <vector>
#include <cmath>
#include <iomanip>
#include <cmath>
typedef long long LL;
typedef unsigned long long LLU;
const double PI=acos(-1.0);
using namespace std;
#define MAXN 100000+10
#define INF 1 << 30
struct Time{
    int x;
    int t;
    friend bool operator < (Time a, Time b){
        return a.t < b.t;
    }
};
int d[MAXN][20];
int wh[MAXN][20];
int main (){
    int n;
    while(scanf("%d",&n) != EOF && n){
        int T = 0;
        memset(wh,0,sizeof(wh));
        memset(d,-1,sizeof(d));
        for(int i = 1; i <= n; i++){
            int x,t;
            scanf("%d%d",&x,&t);
            wh[t][x]++;
            T = max(T, t);
        }
        d[0][5] = 0;
        int M = 0;
        for(int i = 1; i <= T; i++){
            for(int j = 0; j <= 10; j++){
                if((( j >= 1 && d[i-1][j-1] >= 0) || (d[i-1][j+1] >= 0 && j+1 <= 10) || d[i-1][j] >= 0)){
                    if(j >= 1){
                    d[i][j] = max(d[i][j], d[i-1][j-1]+wh[i][j]);}
                    if(j+1 <= 10)
                    d[i][j] = max(d[i][j], d[i-1][j+1]+wh[i][j]);
                    d[i][j] = max(d[i][j], d[i-1][j]+wh[i][j]);
                }
                M = max(d[i][j],M);
            }
        }
        printf("%d\n",M);
    }
    return 0;
}


發佈了141 篇原創文章 · 獲贊 0 · 訪問量 8萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章