2018hdu个人排位赛:米波

将每秒消亡的和生成的单独存数组,每一次都取模操作保证不爆int

模拟1到t秒内的所有情况

#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int a[210],b[210];
inline void init()
{
    memset ( a, 0, sizeof(a) );
    memset ( b, 0, sizeof(b) );
}
int main()
{
    int T ;
    cin>>T;
    while ( T-- )
    {
        init();
        int k,m,t;
        scanf ( "%d%d%d", &k, &m, &t );
        int add = 0,ans = 1;
        a[k]++; b[m]++;
        for (int i=1;i<=t;i++)
        {
            add = ((add+a[i])%mod-b[i]+mod )%mod;
            a[i+k] = (a[i+k]+add)%mod;
            b[i+m] = (b[i+m]+add)%mod;
            ans = ( ans+add )%mod;
            ans = ( ans-b[i]+mod )%mod;
        }
        printf ( "%d\n", ans );
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_41058467/article/details/81022281
今日推荐