HDU6415:Rikka with Nash Equilibrium(dp)
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
2 3 3 100 5 5 2333
Sample Output
64 1170
題意:給個n*m矩陣,用1~n*m填進去,使得Nash equilibriums至多一個,Nash equilibriums值某個數在所在行和列是最大的。
思路:從大到小填進去,dp[i][j][k]表示填了i個數佔了j行k列的方案數,顯然新填一個數要麼j+1要麼k+1要麼都不加,不可能j和k都加,然後遞推下去,加一些判斷優化更快。
# include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 6403;
LL dp[maxn][81][81], mod;
inline void add(LL &a, LL b){
a += b;
if(a > mod) a -= mod;
}
int main()
{
int T, n, m;
for(scanf("%d",&T);T;--T){
scanf("%d%d%lld",&n,&m,&mod);
memset(dp, 0, sizeof(dp));
dp[1][1][1] = n*m;
for(int i=1; i<n*m; ++i){
for(int j=1; j<=n; ++j){
for(int k=1; k<=m; ++k){
if(max(j,k)>i) break;
if(!dp[i][j][k]) continue;
if(j<n) add(dp[i+1][j+1][k], dp[i][j][k]*k%mod*(n-j)%mod);
if(k<m) add(dp[i+1][j][k+1], dp[i][j][k]*j%mod*(m-k)%mod);
if(i<j*k) add(dp[i+1][j][k],dp[i][j][k]*(j*k-i)%mod);
}
}
}
printf("%lld\n",dp[n*m][n][m]);
}
}
相關文章
- HDU 6415 Rikka with Nash Equilibrium (DP)UI
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- hdu 6415 Rikka with Nash EquilibriumUI
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - Rikka with Nash Equilibrium優化UI
- 【dp+組合數學】hdu 2018 多校第九場 1001 Rikka with Nash Equilibrium hdu 6415UI
- 2018 Multi-University Training Contest 9----hdu 6415 Rikka with Nash EquilibriumAIUI
- HDU6415(DP)
- dp 套 dp(dp of dp)小記
- HDU 5831 Rikka with Parenthesis II (括號匹配)
- DP套DP
- [DP] 數位DP
- 【DP】Educational DP Contest
- dp套dp 隨寫
- 【DP】區間DP入門
- dp
- [DP] DP最佳化總結
- 序列 DP
- dp板子
- DP(一)
- six[Dp]
- DP動態規劃-爬塔(雙層dp)動態規劃
- hdu 6415 - DP
- 狀壓 dp
- 揹包DP
- 區間dp
- 樹形DP!
- 機率DP
- dp洩露
- 動態 DP
- DP 詳解
- 狀壓DP
- 數位 dp
- 換根dp
- dp加練
- 換根 DP
- 線性dp
- scientifically practice DP