您的位置:首页 > 其它

SDUT 3895 fireworks 山东第八届ACM大赛C题(组合数学(杨辉三角)+逆元)

2017-06-09 18:44 429 查看
题目地址:点击打开链接

fireworks

Time Limit: 1000MS Memory Limit: 65536KB[align=center]Submit Statistic Discuss[/align]

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 0
2 2
2 2 2
0 3
1 2

Example Output

2
3
【题意】:
在一个数轴上,有n个点有非0值,其余点都为0。
然后,点x的值可以用1秒时间,分别传给左边和右边的一个点。
问T秒后点w的值是多少。

【解析】:
非常类似于一个杨辉三角,思维稍一转变即可。
把每一秒的状态都写成一行,对应在数轴位置,一直往下写,有规律。

询问T秒的位置w时,一共需要从第一行往下走T行,其中一部分向左下走,一部分往右下走。设分别为left和right步。然后从第T行w位置往上回溯到第0行(初始状态)
只需要算一下每一个能到达w的点对w的贡献值即可。

1、假设全部走左路,把左路全排列,A(left,left),
再去重复,除以A(left,left)。(别忘了乘上该起始点的值)
2、假设走一条右路,左路减一。则总路数A(left+1,left+1)
去重复,除以A(left,left),除以A(1,1);
3、再给右路加一条,左路减一。重复此步骤,直到left没有了。

把上面每一个步骤的数据累加,即为answer。

(我的代码,思路应该没问题,但是暂时wrong,,,,仅供参考)
【代码】:#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e6+5;
inline ll inv(ll b){return b<=1?1:(mod-mod/b)*inv(mod%b)%mod;}
ll f
;
int n,T,w;
int main()
{
f[0]=1;
for(int i=1;i<N;i++)f[i]=f[i-1]*i%mod;
while(cin>>n>>T>>w) //T秒后w点的值
{
ll ans=0;
for(int i=0;i<n;i++){
ll x,c;
scanf("%lld%lld",&x,&c);
if((T-w+x)%2||c==0)continue; //没贡献
int L=w-x+(T-w+x)/2;
int R=T-L;
//cout<<" "<<L<<' '<<R<<endl;
if(L<0||R<0)continue;
ll res=f[T]*inv(f[L])%mod*inv(f[R])%mod;
res=res*c%mod;
ans=(ans+res)%mod;
}
cout<<ans<<endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: