C. Ayoub's function-1301C-(贪心+数学+组合)

总结

题意:要求构造一个二进制字符串,求最大的连续字符串包含字符1的方案数
正难反易,求最小的连续的字符串只包含字符0的数量,ans减去它即可
m个1可以构造m+1个空隙
用n-m个0去填就完事

signed main()
{
    IOS;
    //file();
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        int ans=n*(n+1)/2;
        n=n-m;
        m++;
        int a=n/m,b=n%m;
        ans-=a*(a+1)/2*(m-b);
        if(b%m)
            a++;
        ans-=a*(a+1)/2*b;
        cout<<ans<<endl;
    }
    return 0;
}
发布了130 篇原创文章 · 获赞 5 · 访问量 4985

猜你喜欢

转载自blog.csdn.net/weixin_44224825/article/details/104337280