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

都可以吧,不是有spj吗!

Posted by xiaox at 2007-04-08 09:26:16 on Problem 2250
In Reply To:Re:喜欢动态规划的进来!! Posted by:tempfor at 2007-04-08 09:19:57
> 这题:
> a b a
> #
> a a b
> #
> 是输出a a,还是a b,那位大牛看看!!
> 为什么我的程序一直wrong
> #include<iostream>
> #include<string>
> #include<map>
> using namespace std;
> string s1[101],s2[101];
> int f[101][101];
> int la,lb,lc;
> inline int  max(int a,int b)
> {
> 	return a>b?a:b;
> }
> void find(int k,int i,int j)
> {
> 	if(k==0)
> 	{
> 		return;
> 	}
> 	if(f[i][j]==f[i-1][j-1]+1)
> 	{
> 		find(k-1,i-1,j-1);
> 		if(k!=lc)
> 		{
> 			cout<<s1[i]<<' ';
> 		}
> 		else 
> 		{
> 			cout<<s1[i]<<endl;
> 		}
> 	}
> 	else if(f[i][j]==f[i][j-1])
> 	{
> 		find(k,i,j-1);
> 	}
> 	else
> 	{
> 		find(k,i-1,j);
> 	}
> }
> void DP()
> {
> 	int i,j;
> 	memset(f,0,sizeof(f));
> 	for(i=1;i<=la;i++)
> 	{
> 		for(j=1;j<=lb;j++)
> 		{
> 			if(s1[i]==s2[j])
> 			{
> 				f[i][j]=f[i-1][j-1]+1;
> 			}
> 			else
> 			{
> 				f[i][j]=max(f[i-1][j],f[i][j-1]);
> 			}
> 		}
> 	}
> 	lc=f[la][lb];
> 	if(lc==0)
> 	{
> 		cout<<endl;
> 		return;
> 	}
> 	find(lc,la,lb);
> }
> int main()
> {
> 	string temp;
> 	int i=1,j;
> 	while(cin>>s1[i++])
> 	{
> 		if(s1[i-1]=="#")
> 		{
> 			la=i-2;
> 			i=1;
> 			j=1;
> 			while(cin>>s2[j++])
> 			{
> 				if(s2[j-1]=="#")
> 				{
> 					lb=j-2;
> 					DP();
> 					break;
> 				}
> 			}
> 		}
> 	}
> 	return 1;
> }
> 

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