1 条题解

  • 0
    @ 2025-5-25 18:20:37
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    using namespace std;
    
    #define Int register int
    #define MAXN 130
    
    int n;
    double f[MAXN][MAXN],p[MAXN][MAXN];
    
    void read (int &x)
    {
    	x = 0;char c = getchar();int f = 1;
    	while (c < '0' || c > '9'){if (c == '-') f = -f;c = getchar();}
    	while (c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + c - '0';c = getchar();}
    	x *= f;return ;
    }
    
    void write (int x)
    {
    	if (x < 0){x = -x;putchar ('-');}
    	if (x > 9) write (x / 10);
    	putchar (x % 10 + '0');
    }
    
    signed main()
    {
    	while (1)
    	{
    		read (n);
    		if (n == -1) return 0;
    		memset (f,0,sizeof (f));
    		for (Int i = 1;i <= (1ll << n);++ i)
    			for (Int j = 1;j <= (1ll << n);++ j)
    				scanf ("%lf",&p[i][j]);
    		for (Int i = 1;i <= (1ll << n);++ i) f[0][i] = 1.0;
    		for (Int i = 1;i <= n;++ i)
    			for (Int j = 1;j <= (1ll << n);++ j)
    				for (Int k = 1;k <= (1ll << n);++ k)
    					if (((j - 1 >> i - 1) ^ 1) == (k - 1 >> i - 1)) f[i][j] = f[i][j] + f[i - 1][j] * f[i - 1][k] * p[j][k];
    		double maxn = -1;int id = 0; 
    		for (Int i = 1;i <= (1ll << n);++ i)
    			if (f[n][i] > maxn)
    			{
    				maxn = f[n][i];
    				id = i;
    			}
    		write (id),putchar ('\n');
    	}
    	return 0;
    }
    
    
    
    • 1

    信息

    ID
    2072
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    递交数
    1
    已通过
    1
    上传者