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

Re:帮我看一下错在哪里。。。谢谢。是RE.

Posted by direfire at 2007-10-31 16:01:03 on Problem 1240
In Reply To:帮我看一下错在哪里。。。谢谢。是RE. Posted by:direfire at 2007-10-30 19:50:53
还是RE
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>

using namespace std;
int m;
char pre[30], post[30];
int len;

long long v[21][21];

long long parse(char *start, char *end, int l)
{
	if (l == 0) return 1;
	if (l == 1) return 1;
	long long ret = 1;
	int index[27];
	for (int i = 1; i < l; i++)
	   for (int j = 0; j < l-1; j++)
	     if (start[i] == end[j]) { index[i] = j; break;}
	int id = 1;
	int count = 0;
	while(id < l)
	{
		int p = index[id];
		int f = 0;
		char pe[27], po[27];
		memset(pe, '\0', sizeof(pe));
		memset(po, '\0', sizeof(po));
		while(p >= index[id] && id < len) {pe[f] = start[id]; po[f] = end[id-1]; f++; id++;}
	  ret *= parse(pe, po, f);
		count++;
	} 
	ret *= v[m][count];
  return ret;
}

int main()
{
	memset(v, 0, sizeof(v));
	for (int i = 1; i <= 20; i++) v[i][0] = 1;
	v[1][1] = 1;
	for (int i = 2; i <= 20; i++)
		  for (int j = 1; j <= i; j++)
		     v[i][j] = v[i-1][j-1]+v[i-1][j];
  while(1)
  {
    scanf("%d", &m);
    if (m == 0) break;
    memset(pre, '\0', sizeof(pre));	
    memset(post, '\0', sizeof(post));	
    scanf("%s %s", &pre, &post);
    len = strlen(pre);
    long long res = parse(pre, post, len);
    printf("%ld\n", res);
  }
 
	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