885.求组合数 I(模板)
作者:互联网
O(n^2) 数据范围 a*b =4e6
根据组合数公式:
代码:
import java.util.Scanner; public class Main{ static final int N=2005; static final int mod=(int)1e9+7; static int c[][]=new int[N][N]; public static void main(String[] args) { Scanner scan=new Scanner(System.in); for(int i=0;i<N;i++) for(int j=0;j<=i;j++) if(j==0) c[i][j]=1; else c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod; int t=scan.nextInt(); while(t-->0){ int a=scan.nextInt(); int b=scan.nextInt(); System.out.println(c[a][b]); } } }
标签:885,组合,scan,int,System,nextInt,static,模板,Scanner 来源: https://blog.csdn.net/qq_35382207/article/details/113801363