Rikka with Nash Equilibrium

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 1460    Accepted Submission(s): 591

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
 
Source
 
 

在一个矩阵中,如果仅有一个数同时是所在行所在列最大值,那么这个数满足纳什均衡。

构造一个n*m的矩阵,里面填入[1,n*m]互不相同的数字,求有多少种构造方案。

由题可得,满足纳什均衡的数一定是最大值n*m。因此我们可以从大往小依次将数填入矩阵,小数依附于大数的行或列,由此产生的三种行为:

1.所在列有大数,行+1 数+1

2.所在行有大数,列+1 数+1

3.所在行列都有大数,位于交界处,数+1

dp三种状态[占有行数][占有列数][占有个数]进行求解。因为本题数据很强,所以需要以下优化:

1.尽可能得减少取模次数

2.注意状态与遍历顺序保持一致

//记忆化搜索
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod,n,m;
ll dp[][][];
ll dfs(ll x,ll y,ll z){
if(dp[x][y][z]>-) return dp[x][y][z];
ll tmp=;
if(x<n) tmp+=y*(n-x)*dfs(x+,y,z+)%mod;
if(y<m) tmp+=x*(m-y)*dfs(x,y+,z+)%mod;
if(x*y>z) tmp+=(x*y-z)*dfs(x,y,z+)%mod;
return dp[x][y][z]=tmp;
}
int main()
{
ll t;
scanf("%lld",&t);
while(t--){
memset(dp,-,sizeof(dp)); //答案有0的情况,因此初始化为-1
scanf("%lld%lld%lld",&n,&m,&mod);
dp[n][m][n*m]=;
ll ans=n*m*dfs(,,)%mod;
printf("%lld\n",ans);
}
}
//dp
#include<bits/stdc++.h>
#define MAX 82
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll; ll dp[MAX][MAX][]; //注意顺序 int main()
{
int t,n,m,MOD,i,j,k;
scanf("%d",&t);
while(t--){
scanf("%d%d%d",&n,&m,&MOD);
memset(dp,,sizeof(dp));
dp[][][]=n*m;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
for(k=;k<n*m;k++){ //注意顺序
dp[i+][j][k+]+=(n-i)*j*dp[i][j][k];
if(dp[i+][j][k+]>=MOD) dp[i+][j][k+]%=MOD;
dp[i][j+][k+]+=(m-j)*i*dp[i][j][k];
if(dp[i][j+][k+]>=MOD) dp[i][j+][k+]%=MOD;
if(i*j>k){
dp[i][j][k+]+=(i*j-k)*dp[i][j][k];
if(dp[i][j][k+]>=MOD) dp[i][j][k+]%=MOD;
}
}
}
}
printf("%lld\n",dp[n][m][n*m]%MOD);
}
return ;
}

HDU - 6415 多校9 Rikka with Nash Equilibrium(纳什均衡+记忆化搜索/dp)的更多相关文章

  1. hdu 1978 How many ways 记忆化搜索+DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1978 思路很好想: 定义f[i][j]表示从点(i,j)出发到达(n,m)的方法数: 那么对于一切从( ...

  2. hdu 5305 Friends(2015多校第二场第6题)记忆化搜索

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5305 题意:给你n个人,m条关系,关系可以是online也可以是offline,让你求在保证所有人on ...

  3. HDU 1078 FatMouse and Cheese 记忆化搜索DP

    直接爆搜肯定超时,除非你加了某种凡人不能想出来的剪枝...555 因为老鼠的路径上的点满足是递增的,所以满足一定的拓补关系,可以利用动态规划求解 但是复杂的拓补关系无法简单的用循环实现,所以直接采取记 ...

  4. HDU 1078 FatMouse and Cheese (记忆化搜索+dp)

    详见代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <memory. ...

  5. HDU 1142 A Walk Through the Forest(最短路+记忆化搜索)

    A Walk Through the Forest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  6. hdu 4960 记忆化搜索 DP

    Another OCD Patient Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Ot ...

  7. POJ1088 滑雪题解+HDU 1078(记忆化搜索DP)

    Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...

  8. 【杂题总汇】HDU2018多校赛第九场 Rikka with Nash Equilibrium

    [HDU2018多校赛第九场]Rikka with Nash Equilibrium 又是靠这样一道题擦边恰好和第两百名分数一样~愉快

  9. 杭电多校第九场 HDU6415 Rikka with Nash Equilibrium dp

    Rikka with Nash Equilibrium Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K ...

随机推荐

  1. servlet3.0 文件上传功能

    注意 jsp页面中file选择 的要有属性 name='file' package com.webserver.webservice; import java.io.File; import java ...

  2. ios Symbol(s) not found for architecture arm64总结 含隐藏错误cocoapods

    一.通用 报错:Desktop/project/ASDF/WEIXIN/libWeChatSDK.a (3 slices) Undefinedsymbols for architecture arm6 ...

  3. computed 计算属性

    wepyjs - 小程序组件化开发框架 https://tencent.github.io/wepy/document.html#/?id=wepy%e9%a1%b9%e7%9b%ae%e7%9a%8 ...

  4. 取得微信用户OpenID

    公司需要微信这个平台和用户交流,于是开始研究微信公众平台.微信公众平台分为两种模式,其一是编辑模式,比如用户发什么内容,你可以响应什么内容.另外一种便是开发模式,这个模式功能丰富,不仅仅可以获取到用户 ...

  5. Java for LeetCode 100 Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  6. js/jq 动态添加的元素不能触发绑定事件解决方案

    <!-- Copyright 2017-10-27, Jachin QQ: 381558301 Email: 381558301@qq.com 请看看你们的版本并对号入座: jquery1.6版 ...

  7. css3立体旋转菜单

    css3立体旋转菜单,css3,3D,立体旋转,立体菜单,菜单导航,css3立体旋转菜单是一款纯css3实现的三维立体旋转导航菜单. 源码下载页:http://www.huiyi8.com/sc/71 ...

  8. checkbox怎么判断是否选中

    下面这种可以使用 if($("#checkbox1").is(':checked')) { alert("1"); } else { alert("0 ...

  9. 0x01

    随便记录点想法什么的, 这个博客的编辑界面挺简陋的...

  10. linux 进程学习笔记-消息队列messagequeue

    可以想象,如果两个进程都可以访问同一个队列:其中一个进程(sender)向其中写入结构化数据,另外一个进程(receiver)再从其中把结构化的数据读取出来.那么这两个进程就是在利用这个队列进行通信了 ...