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 |
求解我的代码哪里错了?一定要用DP吗?#include <cstdio> #include <iostream> #include <cstring> #include <map> using namespace std; #define MM 5005 char s[MM]; map<char,int>mp; int main() { int n; //freopen("out.txt","r",stdin); while(scanf("%d",&n)!=EOF) { scanf("%s",s); int ans=-1; for(int i=0;i<n;i++) { int tmp=0; mp.clear(); for(int j=0;j<i;j++) mp[s[j]]++; for(int j=i+1;j<n;j++) { if(mp[s[j]]) { tmp++; mp[s[j]]--; } } if(tmp>ans) ans=tmp; } printf("%d\n",n-1-ans*2); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator