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

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

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

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;
}

  

原文地址:https://www.cnblogs.com/l609929321/p/9512338.html

时间: 2024-10-05 10:22:59

杭电多校第九场 HDU6415 Rikka with Nash Equilibrium dp的相关文章

2019杭电多校第九场

2019杭电多校第九场 熟悉的后半场挂机节奏,又苟进首页了,很快乐 1001. Rikka with Quicksort upsolved 不是我做的,1e9调和级数分段打表 1002. Rikka with Cake solved at 01:11 有一个矩形,给你很多射线(射线只有横平竖直的四个方向),问把矩形切成了多少块 队友说答案是交点数加一,作为一个合格的工具人,当然是把队友的想法实现啦 二维坐标离散化枚举纵坐标维护横坐标,常规套路,树状数组也可以做(我是线段树写习惯了根本没想起来还有

Rikka with Game[技巧]----2019 杭电多校第九场:1005

Rikka with Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Though both Rikka and Yuta are busy with study, on their common leisure, they

2019 杭电多校 第九场

2019 Multi-University Training Contest 9 补题链接:2019 Multi-University Training Contest 9 1005 Rikka with Game (HDU 6684) 题意 Rikka 和 Yuta 玩游戏.给定一个字符串.两人轮流对字符串操作.可以选择结束游戏,也可以改变其中一个字符,改变规则是:\(a\rightarrow b,b\rightarrow c,-,y\rightarrow z,z\rightarrow a.\

2019年杭电多校第九场07题(HDU6686+树形dp)

目录 题目链接 题意 思路 代码 题目链接 传送门 题意 定义\(L(a,b)\)为结点\(a\)到结点\(b\)的路径上的结点数,问有种\(pair(L(a,b),L(c,d))\)取值,其中结点\(a\)到结点\(b\)的路径与结点\(c\)到结点\(d\)的路径没有交叉. 思路 我们很容易想到要想两条路径不交叉,那么\(a,b\)与\(c,d\)必定在两棵不同的子树中,假设第一棵子树的直径位\(L1\),第二棵子树的直径为\(L2\),那么我们可以得知\([1,L1]\)必定可以与\([1

2019杭电多校第⑨场B Rikka with Cake (主席树,离散化)

题意: 给定一块n*m的矩形区域,在区域内有若干点,每个顶点发出一条射线,有上下左右四个方向,问矩形被分成了几个区域? 思路: 稍加观察和枚举可以发现,区域数量=射线交点数+1(可以用欧拉定理验证,但是我不会),问题就转变为统计射线交点数量 可以将四个方向的射线分开,用左右的射线去查询与多少个上下的射线相交,先考虑向左的射线A与几条向上的射线相交,设A(x,y),即求(1,x)区间内\(\le y\)的向上的射线条数,显然可以利用主席树进行维护(也可以用树状数组并且更快,但是我不会).其他情况同

hdu-6415 Rikka with Nash Equilibrium dp计数题

http://acm.hdu.edu.cn/showproblem.php?pid=6415 题意:将1~n*m填入一个n*m矩阵 问只有一个顶点的构造方案. 顶点的定义是:某数同时是本行本列的最大值. 题解:考虑最大的那个数,必然是顶点.然后再考虑第二大的,它只能填在上一个数所在的行列.通过这个填法,成果摸出了第一个样例.但完全不会写程序(要分类,递归完全不会写). 后来知道是个O(n*n*m*m)的dp(搜索)orz 直播里的转移方程和代码:dp[i][j][k]代表填了i个数,j行k列已经

【2019.07.22】2019杭电多校第一场

补题地址:http://acm.hdu.edu.cn/listproblem.php?vol=56 题号:6578-6590 1001: 1002:线性基 https://blog.csdn.net/Cassie_zkq/article/details/96979461 1003: 1004: 1005:? 1006: 1007: 1008: 1009: 1010: 1011: 1012: 1013: 自闭场,但补题能学到好多算法和思维,继续加油鸭- 原文地址:https://www.cnblo

2015杭电多校第二场

Buildings Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1622    Accepted Submission(s): 460 Problem Description Your current task is to make a ground plan for a residential building located

2018杭电多校第一场(A)

题意:x+y+z = n , n%x=0,n%y=0,n%z=0,求x*y*z 的最大值 题解: ac code: #include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int t; scanf("%d",&t); while(t--) { ll n; scanf("%lld",&n); n = n*n*n; if(n%27 ==