NOIP 2000 单词接龙 解题报告

  数据不大,直接枚举……嗯,然后就是,比如:1212和1212接龙之后是121212,而不是12121212,就这个注意的,代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char str[20][1001];
char tmp[1001];
int f[20][20];
int used[20];
int ans;
int n;

void srch(int k, int len)
{
	int i;
	if(len > ans){
		ans = len;
	}
	used[k]++;
	for(i = 0; i < n; i++){
		if(f[k][i] > 0 && used[i] < 2){
			srch(i, len + f[k][i]);
		}
	}
	used[k]--;
}

int main(int argc, char **argv)
{
	int i, j;
	char *p, c;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%s\n", str[i]);
	}
	for(i = 0; i < n; i++){
		for(j = 0; j < n; j++){
			strcpy(tmp, str[i]);
			p = &tmp[strlen(tmp) - 1];
			while(p != tmp){
				if(*p == str[j][0] && strncmp(p, str[j], strlen(p)) == 0){
					f[i][j] = strlen(str[j]) - strlen(p);
					break;
				}
				p--;
			}
		}
	}
	scanf("%c", &c);
	for(i = 0; i < n; i++){
		if(str[i][0] == c){
			srch(i, strlen(str[i]));
		}
	}
	printf("%d\n", ans);
	return 0;
}

  

转载于:https://www.cnblogs.com/yylogo/archive/2011/08/17/NOIP-2000-5.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值