杭電多校第九場 HDU6415 Rikka with Nash Equilibrium dp
阿新 • • 發佈:2018-08-21
lar mon 範圍 font fin guarantee stc occurs wing
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.
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.
Rikka with Nash Equilibrium
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1251 Accepted Submission(s): 506
Rikka and Yuta are playing a simple matrix game. At the beginning of the game, Rikka shows an n×m
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
???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)
{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
Source 2018 Multi-University Training Contest 9
Recommend chendu | We have carefully selected several similar problems for you: 6425 6424 6423 6422 6421 題意:
在一個矩陣中,如果某一個數字是該行該列的最大值,則這個數滿足納什均衡。
要求構造一個n*m的矩陣,裏面填的數字各不相同且範圍是【1,m*n】,且矩陣內最多有一個數滿足納什平衡,問有多少種構造方案。
分析:
從大到小往矩陣裏填數,則填的數會多占領一行或者多占領一列或者不占領(上方左方都有比他更大的數)
多占領一行,則這一行可任意填的位置是是這一行還沒填的列
多占領一列,同理
特殊考慮:有更大的數還沒填進去的情況
參考博客:
https://blog.csdn.net/monochrome00/article/details/81875980
AC代碼:
#include <map> #include <set> #include <stack> #include <cmath> #include <queue> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define ls (r<<1) #define rs (r<<1|1) #define debug(a) cout << #a << " " << a << endl using namespace std; typedef long long ll; const ll maxn = 1e6+10; //const ll mod = 998244353; const double pi = acos(-1.0); const double eps = 1e-8; ll n, m, mod, dp[85][85][85*85]; int main() { ios::sync_with_stdio(0); ll t; cin >> t; while( t -- ) { cin >> n >> m >> mod; dp[n][m][n*m] = 1; //占領了n-n+1行m-m+1列,放入了n*m-n*m+1個數字 for( ll k = n*m-1; k >= 1; k -- ) { for( ll i = n; i >= 1; i -- ) { //從最後一行一列開始放最大的數字 for( ll j = m; j >= 1; j -- ) { if( i*j < k ) { break; } dp[i][j][k] = j*(n-i)%mod*dp[i+1][j][k+1]%mod; //多占領了一行,這一行還沒放的位置可以隨意放 dp[i][j][k] = (dp[i][j][k]+i*(m-j)%mod*dp[i][j+1][k+1]%mod)%mod; //多占領了一列,同上 dp[i][j][k] = (dp[i][j][k]+(i*j-k)%mod*dp[i][j][k+1]%mod)%mod; //還有更大的數沒有放進去的情況 } } } cout << n*m%mod*dp[1][1][1]%mod << endl; } return 0; }
杭電多校第九場 HDU6415 Rikka with Nash Equilibrium dp