hdu 1176 简单递推

HDU 1176

题意:中文题

思路:简单递推

AC代码:

#include "iostream"
#include "iomanip"
#include "string.h"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "set"
#include "map"
#include "algorithm"
#include "stdio.h"
#include "math.h"
#pragma comment(linker, "/STACK:102400000,102400000")
#define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
#define mem(a,x) memset(a,x,sizeof(a))
#define step(x) fixed<< setprecision(x)<<
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define ll long long
#define endl ("\n")
#define ft first
#define sd second
#define lrt (rt<<1)
#define rrt (rt<<1|1)
using namespace std;
const long long INF = 1e18+1LL;
const int inf = 1e9+1e8;
const int N=1e5+100;
const ll mod=1e9+7;

int n,dp[3][11];
int M[N][11];
int re(int t, int x){
    return M[t][x];
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    while(cin>>n&&n){
        int tm=0; mem(dp,0), mem(M,0);
        for(int i=1; i<=n; ++i){
            int t,x; cin>>x>>t;
            M[t][x]++; tm=max(tm,t);
        }
        dp[1][4]=re(1,4),dp[1][5]=re(1,5),dp[1][6]=re(1,6);
        int cur=1;
        for(int i=1; i<tm; ++i,cur^=1){
            for(int j=0; j<=10; ++j){
                dp[cur^1][j]=max(dp[cur^1][j],dp[cur][j]+re(i+1,j));
                if(j-1>=0) dp[cur^1][j-1]=max(dp[cur^1][j-1],dp[cur][j]+re(i+1,j-1));
                if(j+1<=10) dp[cur^1][j+1]=max(dp[cur^1][j+1],dp[cur][j]+re(i+1,j+1));
            }
        }
        int ans=0;
        for(int i=0; i<=10; ++i) ans=max(ans,dp[cur][i]);
        cout<<ans<<endl;
    }
    return 0;
}

 

posted on 2017-08-15 15:07  lazzzy  阅读(106)  评论(0编辑  收藏  举报

导航