WA 0样例过不了求助
查看原帖
WA 0样例过不了求助
872662
mengleo楼主2023/11/14 20:57
#include<bits/stdc++.h>

using namespace std;

int n, p[25][25], q[25][25], dp[25][(1 << 20) + 5];

int main()
{
	cin >> n;
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            cin >> p[i][j];
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            cin >> q[i][j];
        }
    }
    for(int i = 1; i <= n; i++)
    {
        for(int s = 0; s < (1 << n); s++)
        {
            for(int j = 1; j <= n; j++)
            {
                if(s & (1 << (j - 1)))
                {
                    continue;
                }
                dp[i][s] = max(dp[i][s], dp[i - 1][s | (1 << (j - 1))] + (p[i][j] * q[j][i]));
            }
        }
    }
    cout << dp[n][(1 << n) - 1];

	return 0;
}
2023/11/14 20:57
加载中...