fireworks
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.
Sample Input
1 2 0 2 2 2 2 2 0 3 1 2
Sample Output
2
3
0000000000100000000 第0s
0000000001010000000 第1s
0000000010201000000
0000000103030100000
0000001040604010000
我们取出来
1
11
121
1331
14641
我们发现是一个杨辉三角(组合数)
如果第一个数不是1,而是其他数。那么对应的其余位置都乘那个数即可。
那么我们就很好处理了,对于t分钟,第i个位置。
我们利用对称性处理右边即可,这样更简单。weizhi=fabs(i-w)//w为我们放第一个数的位置。weizhi就是相对位置,也就是杨辉三角要求的点的实际位置
如果t和weizhi同奇偶,那么就是杨辉三角,否则就是0 C(t,(weizhi+t)/2)
逆原快速求组合数即可。
#include<bits/stdc++.h> using namespace std; const long long maxn=200000; const long long p=1000000007; long long n,t,w; long long jie[110000]; void init() { jie[0]=jie[1]=1; for(int i=2; i<=100000; i++) jie[i]=(jie[i-1]*i)%p; } long long mult(long long a,long long n) { long long ans=1; while(n) { if(n&1)ans=(ans*a)%p; a=(a*a)%p; n>>=1; } return ans; } long long C(long long n,long long m) { return ((jie[n]*mult(jie[n-m],p-2))%p*mult(jie[m],p-2))%p; } int main() { init(); while(cin>>n>>t>>w) { long long ans=0; for(int i=0;i<n;i++) { long long a1,b1; cin>>a1>>b1; long long julu=fabs(a1-w); if((julu&1)==(t&1)&&julu<=t) { ans=(ans+(b1*C(t,(julu+t)/2))%p)%p; } } cout<<ans<<endl; } }