【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
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - 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
- HDU 6415(dp/找規律-2018多校第九場1001)
- HDU多校第九次 6415 (dp
- HDU 6415 (計數dp)
- hdu 6415 - DP
- HDU6415(DP)
- 2020hdu多校8
- HDU 5831 Rikka with Parenthesis II (括號匹配)
- HDU 6415(dp/記憶化搜尋)
- 2020HDU多校第三場 1005 Little W and Contest
- HDU6301 Distinct Values (多校第一場1004) (貪心)
- HDU 2068 RPG的錯排 (錯排+組合數)
- hdu6052 To my boyfriend 2017多校2
- HDU 6311 - Cover [2018杭電多校聯賽第二場 C](尤拉通路/迴路)
- HDU 5816 Hearthstone(狀態壓縮DP+概率)
- hdu 5698 瞬間移動 【質因數分解求組合數】
- HDU 6033 Add More Zero (數學)
- hdu-5384Danganronpa+多校訓練+AC自動機
- HDU 1792 - A New Change Problem(規律,最大不能組合數及其個數)
- 2024杭電多校第九場
- hdu 2111 Saving HDU (DP)
- hdu2084數塔
- 杭電HDU2018 奶牛的故事
- Shape of HDU
- HDU 3349
- 2018 Multi-University Training Contest 3 - HDU ContestAI
- HDU 2052(C語言+註釋)+HDU 2090C語言
- hdu1297大數遞迴遞迴
- Transformation HDU - 4578線段樹綜合操作ORM
- hdu 3879 Base Station (最大權 閉合圖)
- 簡單的揹包問題(入門)HDU2602 HDU2546 HDU1864
- HDU 3661 Assignments