Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

200题留念 留个程序哈

Posted by 737566563 at 2013-01-19 14:41:59 on Problem 2047
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
struct node_type{int l,r,val;}t;
typedef vector<node_type> vnode;
const int maxday=370;
vnode list[maxday];
int n;
int f[maxday][maxday];
int max(int a,int b){return a>b?a:b;}
int max(int a,int b,int c){return max(max(a,b),c);}
void Read(){
    int i;
    for(i=0;i<=365;i++)list[i].clear();
    for(i=1;i<=n;i++)
        scanf("%d%d%d",&t.l,&t.r,&t.val),
        list[t.r].push_back(t);
}
void DP(){
    int i,j,k;
    memset(f,0,sizeof(f));
    for(i=1;i<=365;i++){
        for(k=0;k<list[i].size();k++){
            for(j=1;j<i;j++)
                f[i][j]=max(f[i][j],f[list[i][k].l-1][j]+list[i][k].val);
            for(j=k+1;j<list[i].size();j++)
                f[i][i]=max(f[i][i],f[list[i][k].l-1][list[i][j].l-1]+list[i][k].val+list[i][j].val);
        }
        for(j=1;j<=i;j++){
            f[i][j]=max(f[i][j],f[i-1][j],f[i][j-1]);
            f[j][i]=f[i][j];
        }
    }
    printf("%d\n",f[365][365]);
}
int main(){
    int x,y,d;
    while(scanf("%d",&n)&&n){
        Read();
        DP();
    }
}
解法与下面帖子的做法类似

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator