hdu 5230 整数划分+dp+滚动数组

ZCC loves hacking

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/131072 K (Java/Others)
Total Submission(s): 223    Accepted Submission(s): 92


Problem Description
Now, a Codefires round is coming to end. ZCC has got C(0C106) points by solving all problems. He is amazed that all other contestants in his room have also solved the hardest problem. So he concludes that most contestants are gonna get FST after the contest except the top rated coder Memset137. Before that, ZCC will hack them to make his score higher. There are N(1N100000) other contestants in ZCC's room. They are sorted by their ratings(So Memset137 is the N-th contestant). When ZCC successfully hacks the i-th contestant, he will get i points. You may assume ZCC can hack every wrong solution in very little time, and Memset137 is the contestant with number N. During that time, other contestants won't bother him.

Since ZCC is a modest winner, he doesn't want his score to be too high. ZCC wonders how many ways are there that he can choose some contestants' solutions except the one submitted by Memset137 and hack them so that his final score is between L and R (CLR<C+N) .

Obviously the result can be very large, so please output it modulo 998244353.
 

Input
The first line contains an integer T(T=100) which denotes the number of test cases.
For each test case, there will be four integers N(N105) , C , L , R in a single line.

For 95% of the test cases, N2000 .
For 97% of the test cases, N50000 .
 

Output
For each test case, print a single integer which is the answer.
 

Sample Input
  
  
3 3 0 1 2 5 13 14 17 100 0 23 59
 

Sample Output
  
  
2 6 90567
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=100000+10;

ll dp[maxn][2];
ll sum[maxn];
ll mod=998244353;
int n,c,l,r;
void init()
{
        memset(dp,0,sizeof(dp));
    memset(sum,0,sizeof(sum));
    for(int i=1;i<=maxn-10;i++)
    {
        if(i==1)
        {
            dp[i][0]=0;
            dp[i][1]=1;
        }
        else
        {
            dp[i][0]=1;
            dp[i][1]=0;
        }
        sum[i]=sum[i]+dp[i][0]+dp[i][1];
    }
    for(int i=2;i<450;i++)
    {
        for(int j=1;j<i;j++)
            dp[j][1]=dp[j][0]=0;
        for(int j=i;j<=maxn-10;j++)
        {
             dp[j][1]=dp[j-1][0];
             sum[j]=(sum[j]+dp[j][1])%mod;
        }
        for(int j=i;j<=maxn-10;j++)
        {
            dp[j][0]=(dp[j-i][1]+dp[j-i][0])%mod;
            sum[j]=(sum[j]+dp[j][0])%mod;
        }

    }
    for(int i=2;i<=maxn-10;i++)
        sum[i]=(sum[i-1]+sum[i])%mod;
}
int main()
{
    init();
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d%d",&n,&c,&l,&r);
        l-=c;r-=c;
        ll ans;
        if(l==0)
            ans=(sum[r]+1)%mod;
        else
            ans=(sum[r]-sum[l-1]+mod)%mod;
        cout<<ans<<endl;
    }


}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值