省赛C

来源:互联网 发布:天津网络推广外包 编辑:程序博客网 时间:2024/06/06 00:55

fireworks

Time Limit: 1000MS Memory Limit: 65536KB
Submit Statistic

Problem Description

Hmz likes to play fireworks, especially when they are put regularly.
Now he puts some fireworks in a line. This time he put a trigger on each firework. With that trigger, each firework will explode and split into two parts per second, which means if a firework is currently in position x, then in next second one part will be in position x−1 and one in x+1. They can continue spliting without limits, as Hmz likes.
Now there are n fireworks on the number axis. Hmz wants to know after T seconds, how many fireworks are there in position w?

Input

Input contains multiple test cases.
For each test case:

  • The first line contains 3 integers n,T,w(n,T,|w|≤10^5)
  • In next n lines, each line contains two integers xi and ci, indicating there are ci fireworks in position xi at the beginning(ci,|xi|≤10^5).

Output

For each test case, you should output the answer MOD 1000000007.

Example Input

1 2 02 22 2 20 31 2

Example Output

23

Hint

也就是组合数取模

#include <bits/stdc++.h>using namespace std;const long long mod = 1e9+7;const int maxn = 1e5+10;typedef long long LL;LL fac[maxn];LL modxp(LL a,LL b){    LL res = 1;    while(b){        if(b&1)            res = (res*a)%mod;        b = b>>1;        a = (a*a)%mod;    }    return res;}void Init(){    fac[0] = 1;    for(int i = 1; i < maxn; i++){        fac[i] = (fac[i-1]*i)%mod;    }}LL C(LL a,LL k){    LL re = 1;    while(a && k){        LL aa = a%mod;        LL bb = k%mod;        if(aa<bb)            return 0;        re = re*fac[aa]*modxp(fac[bb]*fac[aa-bb]%mod,mod-2)%mod;        a /= mod;        k /= mod;    }    return re;}int main(){    LL n,t,w,c,x,ans;    Init();    while(~scanf("%lld %lld %lld",&n,&t,&w)){        ans = 0;        while(n--){            scanf("%lld %lld",&x,&c);            LL l = x-t;            LL r = x+t;            LL temp = (w-l);            if(w<l || w>r || temp%2!=0)                continue;            ans = (c*C(t,temp/2))%mod+ans;            ans = ans%mod;        }        printf("%lld\n",ans);    }    return 0;}


0 0
原创粉丝点击