A - Rikka with Nash Equilibrium HDU - 6415

Posted lordxx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A - Rikka with Nash Equilibrium HDU - 6415相关的知识,希望对你有一定的参考价值。

首先可以发现,数字从高到低,每一个数字只能放在已经放了的数字所在的行和列中。
因此我们可以得出一个dp
令dp[k][i][j]表示已经有i行,j列被覆盖,同时拥有k个数字。
所以每一次转移,只会多出一行,或者一列,或者都没有。
这道题极度卡常。我今天比赛交了13发才过,注意模运算,乘法次序等。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<bitset>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b)  for(int i=a;i<b;i++)
#define dw(i,a,b)  for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
typedef unsigned long long ull;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
ll read()
{
    char ch = getchar(); ll x = 0, f = 1;
    while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
typedef pair<int, int> pir;
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lrt root<<1
#define rrt root<<1|1
int T;
int k, n, m;
ll dp[6500][85][85];
int main()
{
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d%d%d", &n, &m, &k);
        int sum = n * m;
        upd(i, 0, n)upd(j, 0, m)upd(p, 0, sum)dp[p][i][j] = 0;
        dp[1][1][1] = n * m;
        upd(p, 1, sum)
        {
            upd(i, 1, n)
            {
                upd(j, 1, m)
                {
                    if (dp[p][i][j])
                    {
                        dp[p + 1][i][j] = (dp[p + 1][i][j] + dp[p][i][j] * ((i*j - p)));
                        if (dp[p + 1][i][j] >= k)dp[p + 1][i][j] %= k;
                        dp[p + 1][i + 1][j] = (dp[p + 1][i + 1][j] + (dp[p][i][j] * j*(n - i))) % k;
                        if (dp[p + 1][i + 1][j] >= k)dp[p + 1][i + 1][j] %= k;
                        dp[p + 1][i][j + 1] = (dp[p + 1][i][j + 1] + (dp[p][i][j] * i*(m - j))) % k;
                        if (dp[p + 1][i][j + 1] >= k)dp[p + 1][i][j + 1] %= k;
                    }
                }
            }
        }
        printf("%lld
", dp[sum][n][m]);
    }
    return 0;
}

以上是关于A - Rikka with Nash Equilibrium HDU - 6415的主要内容,如果未能解决你的问题,请参考以下文章

HDU多校9 Rikka with Nash Equilibrium(记忆化搜索/dp)

杭电多校第九场 HDU6415 Rikka with Nash Equilibrium dp

hdu-6415 Rikka with Nash Equilibrium dp计数题

HDU 5634 Rikka with Phi

图论(生成树):HDU 5631Rikka with Graph

HDU 5631 Rikka with Graph