HDU 6415 Rikka with Nash Equilibrium(计数多维DP+思维)好题。。

Rikka with Nash Equilibrium

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1754    Accepted Submission(s): 717


 

Problem Description

Nash Equilibrium is an important concept in game theory.

Rikka and Yuta are playing a simple matrix game. At the beginning of the game, Rikka shows an n×m integer matrix A . And then Yuta needs to choose an integer in [1,n] , Rikka needs to choose an integer in [1,m] . Let i be Yuta's number and j be Rikka's number, the final score of the game is Ai,j .

In the remaining part of this statement, we use (i,j) to denote the strategy of Yuta and Rikka.

For example, when n=m=3 and matrix A is

⎡⎣⎢111241131⎤⎦⎥


If the strategy is (1,2) , the score will be 2 ; if the strategy is (2,2) , the score will be 4 .

A pure strategy Nash equilibrium of this game is a strategy (x,y) which satisfies neither Rikka nor Yuta can make the score higher by changing his(her) strategy unilaterally. Formally, (x,y) is a Nash equilibrium if and only if:

{Ax,y≥Ai,y  ∀i∈[1,n]Ax,y≥Ax,j  ∀j∈[1,m]



In the previous example, there are two pure strategy Nash equilibriums: (3,1) and (2,2) .

To make the game more interesting, Rikka wants to construct a matrix A for this game which satisfies the following conditions:
1. Each integer in [1,nm] occurs exactly once in A .
2. The game has at most one pure strategy Nash equilibriums.

Now, Rikka wants you to count the number of matrixes with size n×m which satisfy the conditions.  

Input

The first line contains a single integer t(1≤t≤20) , the number of the testcases.

The first line of each testcase contains three numbers n,m and K(1≤n,m≤80,1≤K≤109) .

The input guarantees that there are at most 3 testcases with max(n,m)>50 .

 

Output

For each testcase, output a single line with a single number: the answer modulo K .

 

Sample Input

扫描二维码关注公众号,回复: 2894539 查看本文章
 

2 3 3 100 5 5 2333

 

Sample Output

 

64 1170

 

Source

2018 Multi-University Training Contest 9

 

Recommend

chendu   |   We have carefully selected several similar problems for you:  6437 6436 6435 6434 6433 

#pragma comment(linker, "/STACK:102400000,102400000")
#include<bits/stdc++.h>
using namespace std;

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)

#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ll long long
/*
题目大意:纳什均衡点,
给定n和m,要求填数方案中均衡点只有一个的方案数。

这道题用DP做很明显了,打表找公式听说也可以。。。。
三维DP,下面详解,
dp[k][i][j]表示现在已经放了k个数,已经构造出i行和j列包含最大值的点,(从大到小填数)
也就是说这个局势下有i*j个极大值,
下面考虑转移,如果下一个数不放在i行其中一行,因为是从大到小放,
所以极大值的行和列中行增了一行,而选择有(n-i+1)*j
同理,在列中也有相同的考虑,选择有(m-j+1)*i,
那么如果i和j因为放的数没有增加呢?有这种情况的,
那么选择就有i*j-k+1种。

由于空间被压缩,所以状态转移时要转移干净!
比如判断k和i*j的大小关系时dp该位数组要置零,不然转移会出错,
因为复用了不是完全上一个状态的方案数。

*/


const int  maxn =105;
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}

ll n,m,mod;

ll dp[3][maxn][maxn];

ll ans=0;
int main()
{
    int t;scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld%lld",&n,&m,&mod);

        memset(dp,0,sizeof(dp));
        dp[1][1][1]=n*m%mod;ans=0;
        int flag=1;

        for(ll k=2;k<=n*m;k++)
        {
            flag^=1;
            for(ll i=1;i<=n;i++)
            {
                for(ll j=1;j<=m;j++)
                {
                    dp[flag][i][j]=0;///由于空间的压缩,,,需要重新更新状态
                    if(k>i*j) continue;
                    dp[flag][i][j]=dp[flag^1][i][j]*(i*j-k+1)%mod;///在交叉点放入的选择
                    (dp[flag][i][j]+=dp[flag^1][i-1][j]*(n-i+1)*j)%=mod;
                    (dp[flag][i][j]+=dp[flag^1][i][j-1]*(m-j+1)*i)%=mod;
                    if(k==n*m) (ans+=dp[flag][i][j])%=mod;
                }
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37451344/article/details/82027434
今日推荐