1. Rikka with Nash Equilibrium
  2.  
  3. Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
  4. Total Submission(s): Accepted Submission(s):
  5.  
  6. Problem Description
  7. Nash Equilibrium is an important concept in game theory.
  8.  
  9. 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.
  10.  
  11. In the remaining part of this statement, we use (i,j) to denote the strategy of Yuta and Rikka.
  12.  
  13. For example, when n=m= and matrix A is
  14. ⎡⎣⎢⎢⎤⎦⎥⎥
  15.  
  16. If the strategy is (,), the score will be ; if the strategy is (,), the score will be .
  17.  
  18. 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:
  19. {Ax,yAi,y i∈[,n]Ax,yAx,j j∈[,m]
  20.  
  21. In the previous example, there are two pure strategy Nash equilibriums: (,) and (,).
  22.  
  23. To make the game more interesting, Rikka wants to construct a matrix A for this game which satisfies the following conditions:
  24. . Each integer in [,nm] occurs exactly once in A.
  25. . The game has at most one pure strategy Nash equilibriums.
  26.  
  27. Now, Rikka wants you to count the number of matrixes with size n×m which satisfy the conditions.
  28.  
  29. Input
  30. The first line contains a single integer t(≤t≤), the number of the testcases.
  31.  
  32. The first line of each testcase contains three numbers n,m and K(≤n,m≤,≤K≤).
  33.  
  34. The input guarantees that there are at most testcases with max(n,m)>.
  35.  
  36. Output
  37. For each testcase, output a single line with a single number: the answer modulo K.
  38.  
  39. Sample Input
  40.  
  41. Sample Output
  42.  
  43. Source
  44. Multi-University Training Contest
  45.  
  46. Recommend
  47. chendu

  48. 从大到小填。每次填进去的数都是要在被管住的里面。
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<string.h>
  4. using namespace std;
  5. #define ll long long
  6. ll dp[][][*];
  7. ll n,m,mod;
  8. ll dfs(ll x,ll y,ll z)
  9. {
  10. if(dp[x][y][z]!=-)
  11. return dp[x][y][z];
  12. ll temp=;
  13. if(x<n)
  14. temp=(temp+(y*(n-x)%mod)*dfs(x+,y,z+))%mod;
  15. if(y<m)
  16. temp=(temp+(x*(m-y)%mod)*dfs(x,y+,z+))%mod;
  17. if(x*y>z)
  18. temp=(temp+(x*y-z)%mod*dfs(x,y,z+))%mod;
  19. return dp[x][y][z]=temp;
  20. }
  21. int main()
  22. {
  23. int T;
  24. scanf("%d",&T);
  25. while(T--)
  26. {
  27.  
  28. scanf("%lld%lld%lld",&n,&m,&mod);
  29. memset(dp,-,sizeof dp);
  30. dp[n][m][n*m]=;
  31. ll ans=((n*m)%mod*dfs(,,)%mod);
  32. printf("%lld\n",ans);
  33.  
  34. }
  35.  
  36. return ;
  37. }
  1.  

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

  1.  

hdu6415 记忆化搜索或找规律的更多相关文章

  1. hdu1331&&hdu1579记忆化搜索(DP+DFS)

    这两题是一模一样的``` 题意:给了一系列递推关系,但是由于这些递推很复杂,所以递推起来要花费很长的时间,所以我要编程序在有限的时间内输出答案. w(a, b, c): 如果a,b,c中有一个值小于等 ...

  2. 牛客国庆集训派对Day2 F、平衡二叉树 【构造+记忆化搜索】

    任意门:https://www.nowcoder.com/acm/contest/202/F 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 1048576K,其他语言2097152K6 ...

  3. 记忆化搜索 codevs 2241 排序二叉树

    codevs 2241 排序二叉树 ★   输入文件:bstree.in   输出文件:bstree.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述] 一个边长为n的正三 ...

  4. UVA1629Cake slicing(记忆化搜索)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51190 紫书P305 题意分析:一个矩形蛋糕上有好多个樱桃,现在要 ...

  5. ZOJ3795 Grouping(强连通分量+缩点+记忆化搜索)

    题目给一张有向图,要把点分组,问最少要几个组使得同组内的任意两点不连通. 首先考虑找出强连通分量缩点后形成DAG,强连通分量内的点肯定各自一组,两个强连通分量的拓扑序能确定的也得各自一组. 能在同一组 ...

  6. LightOJ1417 Forwarding Emails(强连通分量+缩点+记忆化搜索)

    题目大概是,每个人收到信息后会把信息发给他认识的一个人如此下去,问一开始要把信息发送给谁这样看到信息的人数最多. 首先找出图中的SCC并记录每个SCC里面的点数,如果传到一个SCC,那么里面的人都可以 ...

  7. HDU 1142 A Walk Through the Forest(SPFA+记忆化搜索DFS)

    题目链接 题意 :办公室编号为1,家编号为2,问从办公室到家有多少条路径,当然路径要短,从A走到B的条件是,A到家比B到家要远,所以可以从A走向B . 思路 : 先以终点为起点求最短路,然后记忆化搜索 ...

  8. poj 1085 Triangle War 博弈论+记忆化搜索

    思路:总共有18条边,9个三角形. 极大极小化搜索+剪枝比较慢,所以用记忆化搜索!! 用state存放当前的加边后的状态,并判断是否构成三角形,找出最优解. 代码如下: #include<ios ...

  9. Codevs_1017_乘积最大_(划分型动态规划/记忆化搜索)

    描述 http://codevs.cn/problem/1017/ 给出一个n位数,在数字中间添加k个乘号,使得最终的乘积最大. 1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提 ...

随机推荐

  1. 原生JS实现表单序列化serialize()

    有一个form表单,要用AJAX后台提交,原来想拼接json,但是数据多了麻烦,不灵活. 用HTML5的FormData来初始化表单 var formdata=new FormData(documen ...

  2. 并查集 P3367 【模板】并查集

    P3367 [模板]并查集 #include<iostream> #include<algorithm> #include<cstdio> #include< ...

  3. JS控制语句(if、for等)、数组(例题)、方法(常用方法介绍)

    控制语句 If if (1>2){ alert() } var a= parseInt(prompt('请输入数字')); if (isNaN(a)) { alert("输入的不是数字 ...

  4. golang 中strconv包用法

    链接:https://studygolang.com/articles/5003 http://www.cnblogs.com/golove/p/3262925.html

  5. Linux笔记 #10# 用于支持Web应用开发&部署&配置的一些自定义脚本

    索引 一.本地开发与测试相关脚本 1.startup.sh 2.shutdown.sh 3.catalina-out.sh 4.localhost_access_log.sh 5.上传本地文件到服务器 ...

  6. JZ2440学习笔记之链接文件lds

    如果在Linux环境下用arm-linux-gcc来编译arm程序,需要编写链接文件lds: 1. 运行地址=链接地址,表示代码在SDRAM中执行的地址,如果程序中有对某部分代码执行过搬运,需要在ld ...

  7. 通过KSoap三方插件解析WebService接口方法

    话不多说,正文如下: 1.在lib中放入ksoap2的jar包并导入 2.在xml 配置文件中加入: <!-- 访问网络的权限 --> <uses-permission androi ...

  8. 数据挖掘领域十大经典算法之—SVM算法(超详细附代码)

    https://blog.csdn.net/fuqiuai/article/details/79483057

  9. 阿里云Hadoop集群DataNode连接不上NameNode

    在logs日志中可以看见DataNode多次去连NameNode,但是都失败了. 经过长时间的研究百度,终于知道了原因. 原因就是安全组限制了端口的开放,所以我们只要把相应的端口打开即可.

  10. shell date命令

    date命令的语法结构: date [-d][时间运算] [+FORMAT] 先说简单的,[+FORMAT] 部分,主要有如下输出格式: 时间方面: %H : 小时(00..23) %I : 小时(0 ...