http://acm.hdu.edu.cn/showproblem.php?pid=6415

Rikka with Nash Equilibrium

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

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
题意:将1 2 3....n*m填入一个n*m的矩阵中,要求最多有一个数既是它所在行的最大值又是其所在列的最大值,求方案数%k的值
题解:由于n*m肯定是其所在行和所在列的最大值,所以可知应该从n*m到1依次填数,保证当前所填数和之前填的数同行或者同列。dp[i][j][q]表示填完当前数之后已经有i行j列被填入数字,q=0表示当前的数填入的位置所在行之前没有被填充,q=1表示所在列之前没有被填充,q=2表示所在行和列都被填充了,可以得到转移方程(1)dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1]+dp[i-1][j][2])%k*(n*j-(i-1)*j)%k; (2)dp[i][j][1]=(dp[i][j-1][0]+dp[i][j-1][1]+dp[i][j-1][2])%k*(m*i-i*(j-1))%k; (3)dp[i][j][2]=(dp[i][j][0]+dp[i][j][1]+dp[i][j][2])%k*((i*j)-(q-1))%k;
 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[][][];
int pre[][];
int main()
{
int t;
scanf("%d",&t);
while(t--){
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
memset(dp,,sizeof(dp));
dp[][][]=n*m;
for(int q=;q<=n*m;q++){
for(int i=min(n,q);i>=;i--){
for(int j=min(m,q-i+);j>=;j--){
if(i*j<q-)break;
dp[i][j][]=(dp[i][j][]+dp[i][j][]+dp[i][j][])%k*((i*j)-(q-))%k;
dp[i][j][]=(dp[i-][j][]+dp[i-][j][]+dp[i-][j][])%k*(n*j-(i-)*j)%k;
dp[i][j][]=(dp[i][j-][]+dp[i][j-][]+dp[i][j-][])%k*(m*i-i*(j-))%k;
}
}
}
printf("%lld\n",(dp[n][m][]+dp[n][m][]+dp[n][m][])%k);
}
return ;
}

注意:这道题如果不通过判断某些条件及时跳出循环就会T掉

[hdoj6415 Rikka with Nash Equilibrium][dp]的更多相关文章

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

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

  2. hdu6415 Rikka with Nash Equilibrium (DP)

    题目链接 Problem Description Nash Equilibrium is an important concept in game theory. Rikka and Yuta are ...

  3. hdu-6415 Rikka with Nash Equilibrium dp计数题

    http://acm.hdu.edu.cn/showproblem.php?pid=6415 题意:将1~n*m填入一个n*m矩阵 问只有一个顶点的构造方案. 顶点的定义是:某数同时是本行本列的最大值 ...

  4. HDU - 6415 多校9 Rikka with Nash Equilibrium(纳什均衡+记忆化搜索/dp)

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

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

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

  6. HDU6415 Rikka with Nash Equilibrium

    HDU6415 Rikka with Nash Equilibrium 找规律 + 大数 由于规律会被取模破坏,所以用了java 找出规律的思路是: 对于一个n*m的矩阵构造,我先考虑n*1的构造,很 ...

  7. HDU 6415 Rikka with Nash Equilibrium (计数DP)

    题意:给两个整数n,m,让你使用 1 ~ n*m的所有数,构造一个矩阵n*m的矩阵,此矩阵满足:只有一个元素在它的此行和此列中都是最大的,求有多种方式. 析:根据题意,可以知道那个元素一定是 n * ...

  8. 三十分钟理解博弈论“纳什均衡” -- Nash Equilibrium

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.技术感兴趣的同学加入. 纳什均衡(或者纳什平衡),Nash ...

  9. HDU 6092 17多校5 Rikka with Subset(dp+思维)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

随机推荐

  1. 经典排序算法及总结(python实现)

    目录 1.排序的基本概念和分类 排序的稳定性: 内排序和外排序 影响内排序算法性能的三个因素: 根据排序过程中借助的主要操作,可把内排序分为: 按照算法复杂度可分为两类: 2.冒泡排序 BubbleS ...

  2. 【闭包】Pants On Fire

    Pants On Fire 题目描述 Donald and Mike are the leaders of the free world and haven’t yet (after half a y ...

  3. asp.net core-1.在控制台创建ASP.NET Core应用程序

    创建asp.net core应用程序,需要先把环境安装好,我这边选的是vs2017 第一步先执行dotnet 我执行dotnet --help可以把所有的命令全部列出来: 红框内就是我们可以用来初始化 ...

  4. AtCoder Grand Contest 040 C - Neither AB nor BA

    传送门 好妙的题啊 首先容易想到简单容斥,统计合法方案数可以考虑总方案数减去不合法方案数 那么先考虑如何判断一个串是否合法,但是直接判断好像很不好搞 这时候就需要一些 $magic$ 了,把所有位置下 ...

  5. 一步一步写News App(一)

    一. 新建一个安卓工程,安卓版本全部选2.3.3 二.第一步,添加一个tabhost控件 在MainActivity中声明TabHost tabHost; 然后新建一个private void ini ...

  6. luogu2657-Windy数题解--数位DP

    题目链接 https://www.luogu.org/problemnew/show/P2657 分析 第一道数位DP题,发现有点意思 DP求\([L,R]\)区间内的XXX个数,很套路地想到前缀和, ...

  7. Python练习_考试第二次

    一. 选择题(32分) 1. python不支持的数据类型有:AA. charB. intC. floatD. list 2. Ex = ‘foo’y = 2print(x + y)A. fooB. ...

  8. 把zTree前的展开收起图标改为三角形,且只有在点击三角形图标时才展开子节点解决方案

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta ht ...

  9. JS 断点调试心得

    1.断点调试是啥?难不难? 断点调试其实并不是多么复杂的一件事,简单的理解无外呼就是打开浏览器,打开sources找到js文件,在行号上点一下罢了.操作起来似乎很简单,其实很多人纠结的是,是在哪里打断 ...

  10. 前端理解控制反转ioc

    工作一直都是写前端,而且都是偏业务的.相关的框架代码层面的了解还是有很大的缺失.一直想多写些维护性,可读性强的代码. 这段时间对控制反转ioc,这样的设计有了一个初步的了解. 前端为弱语言,平时代码的 ...