hdu 6415 Rikka with Nash Equilibrium
Problem Description
Nash Equilibrium is an important concept i 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.
問題描述:
要你構造一個n * m 的矩陣:這個矩陣裡面由數字1 到 n * m構成,要求這個矩陣裡只有一個數是同時是這一行、這一列是最大的(顯然這個數是這個矩陣裡面最大的數也就是n *m,且n*m-1這個數必須與n*m處在同一行或同一列,n*m-2這個數必須與n*m-1或n*m-2處在同一行或同一列,這樣就構成了題目所要求的矩陣)。問你有多少種方法來構造這個矩陣。
綜上所述,我們可以從大到小一個個放數字進去,每放進去一個數字,它的這一行這一列就被佔領(這一行這一列就可以放數字了)。可以發現每放進去一個數字會有三種狀態:
1、多佔領一行;
2、多佔領一列;
3、沒有多佔領。即處在原先佔領行列的交叉口。
然後就可以記憶優化搜尋了,只要寫的不難看是可以剛好卡過的。如果寫成dp的話會更快。
注意記憶優化的陣列初始值不能賦值為零,因為答案也有可能是零。
有一個沒什麼用的優化,如果所有的地方都已經佔領了,那麼剩下的可能數就是一個階乘。不會變快很多,因為剩下的數字相對來說會很小。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod,n,m;
const ll N=6405;
ll dp[85][85][85*85];
ll dfs(ll x,ll y,ll z){
if(dp[x][y][z]!=-1) return dp[x][y][z];
ll tmp=0;
if(x<n) tmp=(tmp+y*(n-x)%mod*dfs(x+1,y,z+1))%mod;
if(y<m) tmp=(tmp+x*(m-y)%mod*dfs(x,y+1,z+1))%mod;
if(x*y>z) tmp=(tmp+(x*y-z)%mod*dfs(x,y,z+1))%mod;
return dp[x][y][z]=tmp;
}
int main(){
ll t;
scanf("%lld",&t);
while(t--){
memset(dp,-1,sizeof(dp));
scanf("%lld%lld%lld",&n,&m,&mod);
dp[n][m][n*m]=1;
ll ans=m*n%mod*dfs(1,1,1)%mod;
printf("%lld\n",ans);
}
}
相關文章
- HDU 6415 Rikka with Nash Equilibrium (DP)UI
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - Rikka with Nash Equilibrium優化UI
- 2018 Multi-University Training Contest 9----hdu 6415 Rikka with Nash EquilibriumAIUI
- 【dp+組合數學】hdu 2018 多校第九場 1001 Rikka with Nash Equilibrium hdu 6415UI
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- 【DFS】HDU 5423 Rikka with Tree
- HDU 5831 Rikka with Parenthesis II (括號匹配)
- HDU5425Rikka with Tree II(數學期望)
- HDU5424Rikka with Graph II(哈密頓圖判斷)
- HDU5831(2016多校第八場)———Rikka with Parenthesis II(水題)
- OpenJDK Nashorn專案介紹JDK
- NFS-Ganasha 高可用配置NFS
- #1280 : Rikka with Sequence II [meet int the middle]
- Java 8 的 Nashorn 指令碼引擎教程Java指令碼
- Nashorn將Javascript帶入企業軟體JavaScript
- SG 函式初步 HDU 1536 && HDU 1944函式
- java8 新特性 v8 nashorn 引擎(五)Java
- gtk-gnash大量佔用cpu解決辦法
- hdu5532
- Shape of HDU
- HDU4787
- JS引擎(2):Java平臺上JavaScript引擎—Rhino/Nashorn概述JSJavaScript
- HDU 2052(C語言+註釋)+HDU 2090C語言
- HDU Find the hotel(RMQ)MQ
- HDU1792(公式)公式
- hdu 2846 Repository
- hdu 1695 GCDGC
- HDU 2051 Bitset
- HDU 2570 迷瘴
- HDU 1729 Stone GameGAM
- 簡單的揹包問題(入門)HDU2602 HDU2546 HDU1864
- Equilibrium腕錶能顯示日月執行規律:天文愛好者必備UI
- HDU 3221Brute-force Algorithm(降冪公式 神似hdu4549)Go公式
- HDU 4858 專案管理專案管理
- HDU 1792 A New Change Problem
- Equivalent Sets(HDU-3836)UI