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

为什么会TLE

Posted by SA17011033 at 2019-09-03 11:02:44 on Problem 3280
#include"iostream"
#include"vector"
#include"stdio.h"
using namespace std;
const int MAXN=2005;

vector<int> cost(30);

int GetMinCost(char* id,int M){
    vector< vector<int> > dp(MAXN,vector<int>(MAXN,0));

    for(int i=0;i<M;i++){
        for(int j=i-1;j>=0;j--){
            if(id[i]==id[j]){
                dp[i+1][j+1]=dp[i][j+2];
            }
            else{
                dp[i+1][j+1]=min(dp[i][j+1]+cost[id[i]-'a'],dp[i+1][j+2]+cost[id[j]-'a']);
            }
        }
    }

    return dp[M][1];
}

int main()
{
 //   freopen("in.txt","r",stdin);
    int N,M;
    char id[MAXN];
    while(scanf("%d%d",&N,&M)==2){
        cin>>id;
        int addCost,delCost;
        char ch;
        for(int i=0;i<N;i++){
            cin>>ch>>addCost>>delCost;
            cost[ch-'a']=min(addCost,delCost);
        }

        cout<<GetMinCost(id,M)<<endl;
    }
    return 0;
}

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