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

题目地址:点击打开链接

fireworks

Time Limit: 1000MS  Memory Limit: 65536KB
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[N];
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;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

雪的期许

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值