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

ac代码!

Posted by mc77xy at 2020-04-02 16:10:44 on Problem 3280
#include<iostream>
#define  js  ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int w[30],n,m,dp[2005][2005];
char s[2005],ch;
int main() {
	int x,y;
	js;
	while(cin>>n>>m) {
		cin>>s;
		for(int i=0;i<n;++i) {
			cin>>ch>>x>>y;
			w[ch-'a']=min(x,y);
		}
		for(int i=m-1;i>=0;--i)
			for(int j=i+1;j<m;++j)
				if(s[i]==s[j])	dp[i][j]=dp[i+1][j-1];
				else	dp[i][j]=min(dp[i+1][j]+w[s[i]-'a'],dp[i][j-1]+w[s[j]-'a']);
		cout<<dp[0][m-1]<<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