山东省第八届 ACM 省赛 fireworks (组合数+逆元)
来源:互联网 发布:淘宝2016年全年销售额 编辑:程序博客网 时间:2024/06/09 23:26
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
题意
烟花在每秒都会分裂一次,并且分裂成的两半刚好落在相邻的两点,然后它们也可以继续分裂。
给出 n
个点烟花的初始数量,问经过 T
秒后在点 w
有多少数量的烟花。
思路
考虑所有的烟花分裂都是一样的,并且其分裂之后所形成的局势仅和时间有关。
所以我们只需要关心一个烟花是如何分裂的:
0 0 0 0 0 1 0 0 0 0 00 0 0 0 1 0 1 0 0 0 00 0 0 1 0 2 0 1 0 0 00 0 1 0 3 0 3 0 1 0 00 1 0 4 0 6 0 4 0 1 0
第几行代表第几秒,行中的每个数字代表当前时间该点烟花的数量,于是我们发现了一个中间插入了 0
的杨辉三角,计算方法也就是组合数咯~
从上面的矩阵我们可以发现,当时间与距离同奇偶的时候才处于杨辉三角中,其余情况都为 0
。
因为题目中数据比较大,所以计算组合数需要用到乘法逆元,先打表求出 n!
,然后根据组合数公式计算即可。
AC 代码
#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>#include<math.h>#include<iostream>using namespace std;#include<queue>#include<map>#define eps (1e-8)const int mod = 1e9+7;typedef long long LL;LL jie[110000];void init(){ jie[0]=jie[1]=1; for(int i=2; i<=100000; i++) jie[i]=(jie[i-1]*i)%mod;}LL mult(LL a,LL n){ LL ans=1; while(n) { if(n&1)ans=(ans*a)%mod; a=(a*a)%mod; n>>=1; } return ans;}LL C(LL n,LL m){ return ((jie[n]*mult(jie[n-m],mod-2))%mod*mult(jie[m],mod-2))%mod;}int main(){ init(); int n,t,w; while(cin>>n>>t>>w) { LL ans=0; for(int i=0; i<n; i++) { LL x,c; cin>>x>>c; LL k=abs(w-x); if((k&1)==(t&1)&&k<=t) ans=(ans+(c*C(t,(k+t)/2))%mod)%mod; } cout<<ans<<endl; } return 0;}
- 山东省第八届 ACM 省赛 fireworks (组合数+逆元)
- Fireworks(山东省第8届ACM省赛)逆元,组合数
- 第八届山东省赛 C sdut 3895 fireworks(组合数+逆元)
- 2017山东省第八届ACM省赛 fireworks(杨辉三角 + 逆元)
- SDUT 3895 (山东省第八届ACM省赛C题) fireworks 杨辉三角+乘法逆元
- 2017年山东省第八届ACM大学生程序设计竞赛 C fireworks(sdut 3895) 逆元求组合数
- 第八届山东acm省赛 C题 fireworks (组合数)
- 端午节个人赛-山东省省赛 fireworks(杨辉三角形+组合数+逆元)
- 山东省第八届acm省赛C题 fireworks
- fireworks 2017年山东省ACM省赛C题 SDUT 3895 (逆元求组合数)
- SDUT 3895 fireworks 山东第八届ACM大赛C题(组合数学(杨辉三角)+逆元)
- 2017山东省第八届ACM省赛 D. HEX(组合数学)
- 山东省第八届acm省赛D题HEX(组合数学)
- HEX----组合数+逆元+思维 山东省第八届省赛D题
- hatuoj 1300 HEX----组合数+逆元+思维 山东省第八届省赛D题
- fireworks----乘法逆元求组合数(2017山东ACM-ICPC省赛)
- 山东省第八届 ACM 省赛 quadratic equation (水、坑)
- 山东省第八届 ACM 省赛 CF (01背包、水)
- #pragma once与 #ifndef的区别
- Java反射机制应用实践
- 随机森林
- 【Unity】制作手游的帧同步时遇到的问题
- CodeFroces 810A Straight «A»
- 山东省第八届 ACM 省赛 fireworks (组合数+逆元)
- AES加解密方式进行加密和解密
- impdp分区表导入错误ORA-14460: 只能指定一个 COMPRESS 或 NOCOMPRESS 子句
- 压力测试计划实例
- androidIPC
- Express
- NestedScrollView嵌套RecyclerView时滑动不流畅问题的解决办法
- 蓝桥杯java第六届决赛第四题--穿越雷区
- Python爬虫模拟登陆豆瓣