zoukankan      html  css  js  c++  java
  • 1119 机器人走方格 V2

    基准时间限制:1 秒 空间限制:131072 KB
    M * N的方格,一个机器人从左上走到右下,只能向右或向下走。有多少种不同的走法?由于方法数量可能很大,只需要输出Mod 10^9 + 7的结果。
     
    Input
    第1行,2个数M,N,中间用空格隔开。(2 <= m,n <= 1000000)
    Output
    输出走法的数量 Mod 10^9 + 7。
    Input示例
    2 3
    Output示例
    3
    思路:打个表找个规律,然后发现是组合数,然后取模费马小定理。
     1 #include<stdio.h>
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<string.h>
     5 #include<queue>
     6 #include<math.h>
     7 using namespace std;
     8 const int mod = 1e9 + 7;
     9 typedef long long LL;
    10 LL N[2000006];
    11 LL quick(LL n,LL m);
    12 int main(void)
    13 {
    14 
    15     N[0] = 1;int i;
    16     for(i = 1; i < 2000001 ;i++)
    17     {
    18         N[i] = (LL)i*(N[i-1])%mod;
    19     }
    20     LL n,m;
    21     cin>>n>>m;
    22     LL x = (n+m-2);
    23     LL ac = N[x-m+1]*N[m-1]%mod;
    24     //printf("%lld
    ",ac);
    25     ac = quick(ac,mod-2);
    26     printf("%lld
    ",ac*N[x]%mod);
    27     return 0;
    28 }
    29 LL quick(LL n,LL m)
    30 {
    31     LL ans = 1;
    32     n%=mod;
    33     while(m)
    34     {
    35         if(m&1)
    36             ans = ans*n %mod;
    37         n = n*n %mod;
    38         m>>=1;
    39     }
    40     return ans;
    41 }
    
    
    油!油!you@
  • 相关阅读:
    nodejs难点
    react 组件化
    vue router & vuex
    vue源码思考
    cookie & session
    servlet
    Hashmap
    Zookeeper+Kafka+flink+socket
    flink consumer can realize kafka avro with overwriting kafkaDeseriler, and executor multithread and genretic extends
    flink kafka consumer with avro schema. handling null
  • 原文地址:https://www.cnblogs.com/zzuli2sjy/p/5813862.html
Copyright © 2011-2022 走看看