hdu6415 记忆化搜索或找规律

Rikka with Nash Equilibrium

Time Limit: / MS (Java/Others)    Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): 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 [,n], Rikka needs to choose an integer in [,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= and matrix A is
⎡⎣⎢⎢⎤⎦⎥⎥ If the strategy is (,), the score will be ; if the strategy is (,), the score will be . 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∈[,n]Ax,y≥Ax,j ∀j∈[,m] In the previous example, there are two pure strategy Nash equilibriums: (,) and (,). To make the game more interesting, Rikka wants to construct a matrix A for this game which satisfies the following conditions:
. Each integer in [,nm] occurs exactly once in A.
. 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(≤t≤), the number of the testcases. The first line of each testcase contains three numbers n,m and K(≤n,m≤,≤K≤). The input guarantees that there are at most testcases with max(n,m)>. Output
For each testcase, output a single line with a single number: the answer modulo K. Sample Input Sample Output Source
Multi-University Training Contest Recommend
chendu

从大到小填。每次填进去的数都是要在被管住的里面。
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
#define ll long long
ll dp[][][*];
ll n,m,mod;
ll dfs(ll x,ll y,ll z)
{
if(dp[x][y][z]!=-)
return dp[x][y][z];
ll temp=;
if(x<n)
temp=(temp+(y*(n-x)%mod)*dfs(x+,y,z+))%mod;
if(y<m)
temp=(temp+(x*(m-y)%mod)*dfs(x,y+,z+))%mod;
if(x*y>z)
temp=(temp+(x*y-z)%mod*dfs(x,y,z+))%mod;
return dp[x][y][z]=temp;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{ scanf("%lld%lld%lld",&n,&m,&mod);
memset(dp,-,sizeof dp);
dp[n][m][n*m]=;
ll ans=((n*m)%mod*dfs(,,)%mod);
printf("%lld\n",ans); } return ;
}

找规律看https://www.cnblogs.com/solvit/p/9507207.html

 
上一篇:js实现网页收藏功能,动态添加删除网址


下一篇:嵌入式linux驱动开发之点亮led(驱动编程思想之初体验)