[UVA1637]Double Patience && 概率

一直以为只要连着两个数组a b 一起开就可以直接memset(a, 0, sizeof(a) + sizeof(b)) 结果果断RE了 而且一直不懂 只道hlq大神告诉我这个错了我才知道 我猜可能只有开在一行的才行吧  或者是相同类型?


九维数组表示当前每一堆排的状态 然后直接枚举可行操作算概率 就这样= = 

#include<cstdio>
#include<algorithm>
#include<cstring>
#define dNow d[s1][s2][s3][s4][s5][s6][s7][s8][s9]
#define vNow vis[s1][s2][s3][s4][s5][s6][s7][s8][s9]
#define SF scanf
#define PF printf
using namespace std;
const int MAXN = 5;
double d[MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1];
bool vis[MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1][MAXN+1];
char s[5][10], A[10][10];
int n = 9;
double dfs(int s1, int s2, int s3, int s4, int s5, int s6, int s7, int s8, int s9)
{
	if(vNow) return dNow;
	vNow = true;
	bool ok = true;
	double cnt = 0, &ans = dNow;
	int	tot = 0;
	int T[10] = { 0, s1, s2, s3, s4, s5, s6, s7, s8, s9 };
	for(int i = 1; i <= n; i++) if(T[i]) { ok = false; break; }
	if(ok) return ans = 1.0;
	for(int i = 1; i <= n; i++) 
	{
		if(!T[i]) continue;
		for(int j = i + 1; j <= n; j++)
		{
			if(A[i][T[i]] == A[j][T[j]])
			{
				T[i]--; T[j]--; tot++;
				cnt += dfs(T[1], T[2], T[3], T[4], T[5], T[6], T[7], T[8], T[9]);
				T[i]++; T[j]++;
			}
		}
	}
	if(cnt > 0) ans = cnt / (1.0 * tot);
	return ans;
}	
int main()
{
	while(~SF("%s%s%s%s", s[1], s[2], s[3], s[4]))
	{
		memset(d, 0, sizeof(d) + sizeof(vis)); 
		for(int i = 1; i <= 4; i++) A[1][i] = s[i][0];
		for(int j = 2; j <= 9; j++)
		{
			SF("%s%s%s%s", s[1], s[2], s[3], s[4]);
			for(int i = 1; i <= 4; i++) A[j][i] = s[i][0];
		}
		dfs(4, 4, 4, 4, 4, 4, 4, 4, 4);
		PF("%lf\n", d[4][4][4][4][4][4][4][4][4]);
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值