W small candy

Topic connection:  https://ac.nowcoder.com/acm/contest/923/C

   Be a problem to find the law, after the latter because people will be more than the previous one, can be understood as a person before a person to inherit, sum for the current number of candy, candy add much more for the next person to person than the previous one, num is the number a third method are made of sugar,

  Third after hair sugar method ratios in previous much as 35,791,113 So add + = num * 2, sum + = add, add + = number of the second person, beginning tag at where to start from start to finish can be a general sweep, said more chaos, this question is quite miss, but difficult to understand

 

  AC Code:

 

  

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
ll vis[100010][3];
ll ans[100010];
int main()
{
    ll t;
    scanf("%lld",&t);
    while(t--){
        ll m,n;
        scanf("%lld %lld",&m,&n);
        memset(vis,0,sizeof(vis));
        for(ll i=0;i<n;i++){
            ll a,b;
            scanf("%lld %lld",&a,&b);
            vis[b][a-1]++;
        }
        ll add=0;
        ll sum=0;
        ll ge=0;
        for(ll i=1;i<=m;i++){
            for(ll j=0;j<3;j++){
                sum+=vis[i][j];
                sum%=mod;
            }
            sum+=add;
            sum%=mod;
            ge+=vis[i][2];
            ge%=mod;
            add+=vis[i][1];
            add%=mod;
            add+=vis[i][2];
            add%=mod;
            add+=ge*2;
            add%=mod;
            printf("%lld",sum);
            if(i!=m) printf(" ");
        }
        printf("\n");
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/fzw1523/p/11071757.html