站外题求助(悬关
  • 板块学术版
  • 楼主Ryzen_9_9950X3D
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/3 21:22
  • 上次更新2024/10/3 23:58:42
查看原帖
站外题求助(悬关
1023961
Ryzen_9_9950X3D楼主2024/10/3 21:22

#include <bits/stdc++.h>
using namespace std;
#define int long long
map<char,pair<int,int>> p;
int ans = 0,r;
const string s = "BESSIE-GOES-MOO";
vector<int> z;
void dfs(int depth,int state,bool h1,bool h2,bool h3,int p1,int p2,int p3)
{
	if(depth == s.size())
	{
		if((h1 && h2) && h3 == false)
		{
			int tmp = p1;
			tmp *= p2;
			tmp *= p3;
			ans += tmp;
		}
		return;
	}
	if(s[depth] == '-')
	{
		/*if(state == 1 && p1)
		{
			for(int i = 0;i < 6;i++) cout << z[i] << " ";
			cout << endl;
		}*/
		dfs(depth + 1,state + 1,h1,h2,h3,p1,p2,p3);
		return;
	}
	if(state == 1)
	{
		z.push_back(0);
		dfs(depth + 1,state,h1,h2,h3,p1 * p[s[depth]].first,p2,p3);
		z.pop_back();
		z.push_back(1);
		dfs(depth + 1,state,!h1,h2,h3,p1 * p[s[depth]].second,p2,p3);
		z.pop_back();
		return;
	}
	if(state == 2)
	{
		z.push_back(0);
		dfs(depth + 1,state,h1,h2,h3,p1,p2 * p[s[depth]].first,p3);
		z.pop_back();
		z.push_back(1);
		dfs(depth + 1,state,h1,!h2,h3,p1,p2 * p[s[depth]].second,p3);
		z.pop_back();
		return;
	}
	if(state == 3)
	{
		z.push_back(0);
		dfs(depth + 1,state,h1,h2,h3,p1,p2,p3 * p[s[depth]].first);
		z.pop_back();
		z.push_back(1);
		dfs(depth + 1,state,h1,h2,!h3,p1,p2,p3 * p[s[depth]].second);
		z.pop_back();
		return;
	}
}
signed main()
{
	r = s.size();
	p['B'].first = p['B'].second = 0;
	p['E'].first = p['E'].second = 0;
	p['S'].first = p['S'].second = 0;
	p['I'].first = p['I'].second = 0;
	p['G'].first = p['G'].second = 0;
	p['M'].first = p['M'].second = 0;
	p['O'].first = p['O'].second = 0;
	int n;
	cin >> n;
	char u;
	int v;
	for(int i = 1;i <= n;i++)
	{
		cin >> u >> v;
		if(v % 2 == 1) p[u].second++;
		else p[u].first++;
	} 
	dfs(1,1,false,false,false,1,1,1);
	cout << ans;
	return 0;
}
2024/10/3 21:22
加载中...