UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#213915#2662. 折跃WZRYWZWY1001997ms98824kbC++112.0kb2024-11-14 18:45:002024-11-14 23:00:37

answer

#include <iostream> // https://www.cnblogs.com/zhangchengc919/p/5843927.html
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack>
#include <map>
   
using namespace std;
   
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
   
typedef  long long LL;
   
template<class T> void read(T&num) {
    char CH; bool F=false;
    for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
    for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
    F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
    if(!p) { puts("0"); return; }
    while(p) stk[++ tp] = p%10, p/=10;
    while(tp) putchar(stk[tp--] + '0');
    putchar('\n');
}
   
const int mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e6+20;
const int maxn=5e3+5;
const double eps=1e-12;
  
int n,a,b,k;
int dp[maxn][maxn];
 
inline void solve(int d,int l,int r,int val)
{
    if(l>r)return ;
    dp[d][l]+=val;
    if(dp[d][l]>=mod)dp[d][l]-=mod;
    dp[d][r+1]-=val;
    if(dp[d][r+1]<0)dp[d][r+1]+=mod;
}
int main()
{
    read(n);read(a);read(b);read(k);
    for(int i=0;i<=n;i++)for(int j=0;j<=k;j++)dp[i][j]=0;
    int len=abs(b-a)-1;
    int l=max(1,a-len),r=min(n,a+len);
    for(int i=l;i<=r;i++)if(i!=b&&i!=a)dp[1][i]=1;
    for(int i=n;i>0;i--)
    {
        dp[1][i]=dp[1][i]-dp[1][i-1];
        if(dp[1][i]<0)dp[1][i]+=mod;
    }
    for(int i=1;i<k;i++)
    {
        int sum=0;
        for(int j=1;j<=n;j++)
        {
            sum=sum+dp[i][j];
            if(sum>=mod)sum-=mod;
            if(j==b)continue;
            len=abs(j-b)-1;
            l=max(1,j-len);r=min(n,j+len);
            solve(i+1,l,j-1,sum);
            solve(i+1,j+1,r,sum);
        }
    }
    int ans=0,sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=dp[k][i];
        if(sum>=mod)sum-=mod;
        ans+=sum;
        if(ans>=mod)ans-=mod;
    }
    cout<<ans<<"\n";
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1592kb

input:

98 18 22 94

output:

27076018

result:

ok single line: '27076018'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1580kb

input:

95 94 73 92

output:

748455277

result:

ok single line: '748455277'

Test #3:

score: 10
Accepted
time: 281ms
memory: 98604kb

input:

4674 2740 4172 4983

output:

454585991

result:

ok single line: '454585991'

Test #4:

score: 10
Accepted
time: 297ms
memory: 98824kb

input:

4981 813 4046 4994

output:

226418975

result:

ok single line: '226418975'

Test #5:

score: 10
Accepted
time: 273ms
memory: 95220kb

input:

4595 3757 519 4810

output:

194357577

result:

ok single line: '194357577'

Test #6:

score: 10
Accepted
time: 213ms
memory: 97024kb

input:

4902 277 2317 4821

output:

641852228

result:

ok single line: '641852228'

Test #7:

score: 10
Accepted
time: 282ms
memory: 98744kb

input:

4516 1607 639 4990

output:

973001631

result:

ok single line: '973001631'

Test #8:

score: 10
Accepted
time: 255ms
memory: 95476kb

input:

4823 1127 3840 4648

output:

431104558

result:

ok single line: '431104558'

Test #9:

score: 10
Accepted
time: 193ms
memory: 97704kb

input:

4937 3261 2918 4817

output:

638296884

result:

ok single line: '638296884'

Test #10:

score: 10
Accepted
time: 203ms
memory: 95572kb

input:

4744 135 2414 4828

output:

30641258

result:

ok single line: '30641258'