Codeforces Bubble Cup 8 - Finals [Online Mirror]H. Bots 数学

H. Bots

Time Limit: 1 Sec  

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/575/problem/H

Description

Sasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. The game is cooperative and turn based. In each turn, one of the players makes a move (it doesn’t matter which player, it's possible that players turns do not alternate).

Algorithm for bots that Sasha and Ira are developing works by keeping track of the state the game is in. Each time either bot makes a move, the state changes. And, since the game is very dynamic, it will never go back to the state it was already in at any point in the past.

Sasha and Ira are perfectionists and want their algorithm to have an optimal winning strategy. They have noticed that in the optimal winning strategy, both bots make exactly N moves each. But, in order to find the optimal strategy, their algorithm needs to analyze all possible states of the game (they haven’t learned about alpha-beta pruning yet) and pick the best sequence of moves.

They are worried about the efficiency of their algorithm and are wondering what is the total number of states of the game that need to be analyzed?

Input

The first and only line contains integer N.

  • 1 ≤ N ≤ 106

Output

Output should contain a single integer – number of possible states modulo 109 + 7.

Sample Input

2

Sample Output

 19

HINT

 

题意

有两个人,问你两个人都走n次的状态一共有多少种

题解:

打表打表,然后推推数学

推出来是这个:2*(2*n-1)!/(n!*(n-1)!)-1

那就随便搞搞就好啦

代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll Mod=1000000007LL;
ll f[2000010];
void build()
{
    f[0]=1LL;
    for(int i=1;i<=2000005;i++)
        f[i]=i*f[i-1]%Mod;
}
ll fp(ll a,ll k)
{
    ll res=1LL;
    while(k)
    {
        if(k&1)res=res*a%Mod;
        a=a*a%Mod;
        k>>=1;
    }
    return res;
}
ll C(int n,int k)
{
    if(k>n)return 0LL;
    return f[n]*fp(f[k],Mod-2)%Mod*fp(f[n-k],Mod-2)%Mod;
}
int main()
{
    build();
    int n;
    scanf("%d",&n);
    n++;
    ll ans=(2*C(2*n-1,n)+Mod-1)%Mod;
    printf("%I64d\n",ans);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值