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 Matrixking at 2012-06-18 19:43:54 on Problem 1159
#include<stdio.h>
#define POS(I,J) ((1+(J))*(J)/2+(I))
const int maxn=5000;
int d[(1+maxn)*maxn/2],N;//压缩矩阵
char str[maxn+1];
int min(int a,int b)
{
	if(a<b)return a;
	else return b;
}
int main()
{
	int i,j,p;
	scanf("%d%s",&N,str);
	for(p=1;p<N;p++)
	{
		for(i=0;i+p<N;i++)
		{
			j=i+p;
			if(str[i]==str[j])d[POS(i,j)]=i+1<=j-1?d[POS(i+1,j-1)]:0;
			else d[POS(i,j)]=min(d[POS(i+1,j)]+1,d[POS(i,j-1)]+1);
		}
	}
	printf("%d",d[POS(0,N-1)]);
	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