zoukankan      html  css  js  c++  java
  • hdu6415 记忆化搜索或找规律

    Rikka with Nash Equilibrium
    
    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
    Total Submission(s): 1479    Accepted Submission(s): 599
    
    
    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
     
    从大到小填。每次填进去的数都是要在被管住的里面。
    #include<iostream>
    #include<cstdio>
    #include<string.h>
    using namespace std;
    #define ll long long
    ll dp[81][81][81*81];
    ll  n,m,mod;
    ll dfs(ll  x,ll  y,ll z)
    {
        if(dp[x][y][z]!=-1)
            return dp[x][y][z];
        ll temp=0;
        if(x<n)
            temp=(temp+(y*(n-x)%mod)*dfs(x+1,y,z+1))%mod;
        if(y<m)
            temp=(temp+(x*(m-y)%mod)*dfs(x,y+1,z+1))%mod;
        if(x*y>z)
            temp=(temp+(x*y-z)%mod*dfs(x,y,z+1))%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,-1,sizeof dp);
            dp[n][m][n*m]=1;
            ll ans=((n*m)%mod*dfs(1,1,1)%mod);
            printf("%lld
    ",ans);
            
        }
       
    
        return 0;
    }
    
    

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

     
  • 相关阅读:
    (转载) 随机数原理
    ZOJ 2588 Burning Bridges(求桥的数量,邻接表)
    生成不重复的随机数对(C/C++)
    比较两个文件是否相同(C/C++语言)
    计算文件大小(C/C++语言)
    (转载)Nim游戏博弈(收集完全版)
    将一串字符串全排列输出(回溯法)
    Linux中使用Crontab定时监测维护Tomcat应用程序的方法
    Nginx单向认证的安装配置
    非关系型数据库 2017-02-12 22:27 189人阅读 评论(2) 收藏
  • 原文地址:https://www.cnblogs.com/2014slx/p/9515501.html
Copyright © 2011-2022 走看看