Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
压缩矩阵AC#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator