HDU6415 Rikka with Nash Equilibrium

找规律 + 大数

由于规律会被取模破坏,所以用了java

找出规律的思路是:

对于一个n*m的矩阵构造,我先考虑n*1的构造,很容易知道它是n!种方法。然后对于n*2的矩阵构造,就是在n*1的矩阵中新加入n个元素的排列组合,当然这里面一定会有非法的情况。通过打表可以暴力的搜出5*5以内的答案,所以我就可以知道从n*1的矩阵扩展到n*2的矩阵中有多少种非法组合(n <= 5 只知道小数据)。同理对于n*2扩展到n*3以后到n*(m-1)扩展到n*m的正确方案数和每次剔除的方案数就可以得到(小数据暴力得到)。然后发现规律 每次正确合法方案数:非法方案数 = i :(n-1);i从2迭代到m就可以得到答案。

java版本:

//package acm;

import java.math.BigInteger;
import java.awt.Container;
import java.math.*;
import java.math.BigInteger;
import java.util.*;

import org.omg.PortableServer.ID_ASSIGNMENT_POLICY_ID; 
public class Main
{    
     
    
       public static void main(String[] args) 
       {            
           Scanner cin=new Scanner(System.in);
           int t = cin.nextInt();
           for(int i=1;i<=t;i++)
           {
               int n = cin.nextInt();
               int m = cin.nextInt();
               BigInteger k = cin.nextBigInteger();
               
               if(n==1)
               {
                   BigInteger ans = BigInteger.ONE;
                   for(int j=1;j<=m;j++)
                   {
                       ans = ans.multiply(BigInteger.valueOf(j));
                   }
                   ans = ans.mod(k);
                   System.out.println(ans);
               }
               else {
                   BigInteger ans1 = BigInteger.ONE;
                   for(int j=1;j<=n;j++)
                   {
                       ans1 = ans1.multiply(BigInteger.valueOf(j));
                   }
                   
                   //System.out.println(ans1);
                   for(int j=2;j<=m;j++)
                   {
                       BigInteger tt = BigInteger.valueOf(j*n);
                       BigInteger temp = BigInteger.ONE;
                       for(int kk=0;kk<n;kk++)
                       {
                           temp = temp.multiply(tt.subtract(BigInteger.valueOf(kk)));
                       }
                       ans1 = ans1.multiply(temp);
                       ans1 = ans1.multiply(BigInteger.valueOf(j)).divide(BigInteger.valueOf(j+n-1));
                       
                   }
                   ans1 = ans1.mod(k);
                   System.out.println(ans1);
               }
           }
           cin.close();
      }
}
View Code

相关文章:

  • 2021-11-25
  • 2022-12-23
  • 2022-02-07
  • 2021-07-08
  • 2021-06-13
  • 2021-10-14
  • 2021-05-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-14
  • 2022-12-23
  • 2021-09-17
  • 2021-05-15
相关资源
相似解决方案