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吗?

Posted by 1304010110 at 2014-07-16 09:22:25 on Problem 1159
#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:
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