c本地测试没问题 洛谷全WA read-
查看原帖
c本地测试没问题 洛谷全WA read-
1332946
wendi03楼主2024/4/12 20:49
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

char s1[1005];
char s2[1005];//相反的 
int dp[1005][1005];//dp[i][j]到第i位 第j位 相同的数量 

int themax(int a,int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}

int main(int argc, char *argv[]) {
	scanf("%s",&s1);
	int len=strlen(s1);

	int i=0;
	for(i;i<len;i++){
		s2[i]=s1[len-i-1];
	}
	i=0;
	for(i;i<len;i++){
		int j=0;
		for(j;j<len;j++){
			if(s1[i]==s2[j]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=themax(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	int ans=len-dp[len-1][len-1];

	printf("%d",len-dp[len-1][len-1]);
	return 0;
}
2024/4/12 20:49
加载中...