20pts AC #1 #2 玄关
  • 板块P1278 单词游戏
  • 楼主hehehy
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/25 20:22
  • 上次更新2024/3/25 21:46:56
查看原帖
20pts AC #1 #2 玄关
1036685
hehehy楼主2024/3/25 20:22
#include<bits/stdc++.h>
using namespace std;
int n,f[20][(1<<17)],l[20],r[20],w[20],ans;
string a;
map<char,int> m;
int main(){
	cin>>n;
	m['A']=1;
	m['E']=2;
	m['I']=3;
	m['O']=4;
	m['U']=5;
	for(int i=1;i<=n;i++){
		cin>>a;
		l[i]=m[a[0]];
		r[i]=m[a[a.size()-1]];
		f[i][(1<<(i-1))]=w[i]=a.size();
	}
	for(int i=1;i<(1<<n);i++){
		for(int j=1;j<=n;j++){
			if((i^(1<<(j-1)))>i){
				for(int v=1;v<=n;v++){
					if((i^(1<<(v-1)))<i&&r[v]==l[j]){
//						cout<<j<<" "<<v;
						f[j][(i^(1<<(j-1)))]=max(f[j][(i^(1<<(j-1)))],f[v][i]+w[j]);
					}
				}
			}
		}
//		for(int j=1;j<=n;j++){
//			cout<<f[j][i]<<" ";
//		}
//		cout<<"\n";
	}
	for(int i=1;i<=n;i++){
		ans=max(ans,f[i][(1<<n)-1]);
	}
	cout<<ans;
	return 0;
} 
2024/3/25 20:22
加载中...