【dp+組合數學】hdu 2018 多校第九場 1001 Rikka with Nash Equilibrium hdu 6415
Rikka with Nash Equilibrium
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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
dp計算放置多少行多少列所可能得到的情況
增加新的點增加新的一行
增加新的點增加新的一列
增加新的點不增加行列:放在交點
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[6455][85][85]; //dp[i][j][k]:有i個點,佔據了j行k列有幾種放法
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,mod;
scanf("%d%d%d",&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++)
{
dp[i+1][j+1][k]=dp[i+1][j+1][k]+(n-j)*k*dp[i][j][k]; //佔據的新的一行所能放的可能
dp[i+1][j][k+1]=dp[i+1][j][k+1]+(m-k)*j*dp[i][j][k]; //佔據的新的一列所能放的可能
if(dp[i+1][j+1][k]>=mod) dp[i+1][j+1][k]%=mod; //mod太多會超時,微弱優化
if(dp[i+1][j][k+1]>=mod) dp[i+1][j+1][k]%=mod;
ll p=j*k-i; //計算有多少個可以放的交點
if(p<=0) continue; //不能放就跳過
dp[i+1][j][k]=dp[i+1][j][k]+p*dp[i][j][k]; //放交點不增加行列
if(dp[i+1][j][k]>=mod) dp[i+1][j][k]%=mod;
}
}
}
printf("%lld\n",dp[n*m][n][m]%mod);
}
return 0;
}
相關文章
- hdu 6415 Rikka with Nash EquilibriumUI
- HDU 6415 Rikka with Nash Equilibrium (DP)UI
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - Rikka with Nash Equilibrium優化UI
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- 2018 Multi-University Training Contest 9----hdu 6415 Rikka with Nash EquilibriumAIUI
- HDU5425Rikka with Tree II(數學期望)
- HDU4965Fast Matrix Calculation(2014多校第九場)AST
- HDU5831(2016多校第八場)———Rikka with Parenthesis II(水題)
- 【DFS】HDU 5423 Rikka with Tree
- HDU 4497 GCD and LCM(拆素數+組合)GC
- HDU 2582 f(n) (組合數的gcd)GC
- HDU 5831 Rikka with Parenthesis II (括號匹配)
- HDU 5389 Zero Escape(2015年多校聯合第八場 動態規劃)動態規劃
- HDU 4465 Candy(組合+log優化)優化
- hdu5289||2015多校聯合第一場1002貪心+RMQMQ
- HDU5424Rikka with Graph II(哈密頓圖判斷)
- hdu 4546 優先佇列 數列組合和第m小佇列
- HDU 1792 - A New Change Problem(規律,最大不能組合數及其個數)
- hdu5336 多校聯合第四場1010 模擬+bfs優先佇列佇列
- 2014多校聯合第9場1011題||hdu 4970 樹狀陣列陣列
- HDU4427Math Magic (dp+滾動陣列)陣列
- HDU 3530 Subsequence (dp+單調佇列)佇列
- 2014多校聯合第9場1006||hdu 4965 矩陣乘法和快速冪矩陣
- HDU 5375 Gray code(2015年多校聯合 動態規劃)動態規劃
- 2014多校聯合第十場A題||hdu 4971 最小割定理在最大權閉合圖上的應用
- 2020HDU多校第三場 1005 Little W and Contest
- 2024杭電多校第九場
- 【數學】組合數學 - 排列組合
- HDU 4427 Math Magic【dp+優化+滾動陣列】【好題】優化陣列
- HDU3519Lucky Coins Sequence(DP+矩陣加速)矩陣
- HDU4991 Ordered Subsequence (dp+樹狀陣列+離散化)陣列
- 數學規律題,數論知識:hdu1792
- hdu5414(2015多校10)--CRB and String(字串匹配)字串匹配
- HDU 2662 Coin && HDU 1792 A New Change Problem (互質數最大不能生成數)
- 組合數學
- hdu3001 狀態壓縮dp+三進位制