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

简单的dp,注意用int型会爆空间,好猥琐

Posted by KatrineYang at 2016-07-19 23:18:19 on Problem 1159
#include <iostream>
#include <string>
using namespace std;

short res[5005][5005] = {0};

int main() {
	string s;
	int len;
	cin >> len >> s;
	for(int cha = 1; cha < len; cha ++){
		for(int i = 0; i < len - cha; i++){
			int j = i + cha;
			short min = 5005;
			if(min > 1 + res[i+1][j]) min = 1 + res[i+1][j];
			if(min > 1 + res[i][j-1]) min = 1 + res[i][j-1];
			if(s[i] == s[j] && min > res[i+1][j-1]) min = res[i+1][j-1];
			res[i][j] = min;
		}
	}
	cout << res[0][len-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