ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#186617 | #3353. 雨落玫瑰 | Harry27182 | 100 | 3756ms | 423428kb | C++11 | 2.3kb | 2023-10-01 10:18:40 | 2023-10-01 12:36:48 |
answer
#include<bits/stdc++.h>
using namespace std;
int f[25005][30][30][2],g[25005][30][30][2],id[25005][30],id2[25005][30];
int tot[25005],tot2[25005],n,k,ans,a[25005];map<int,int>mp[25005],mp2[25005];
const int mod=1000000007;
void Add(int &x,int y){x=(x+y>=mod?x+y-mod:x+y);}
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
f[0][1][0][0]=1;tot[0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=tot[i-1];j++)
{
for(int p=0;p<=k;p++)
{
for(int q=0;q<=1;q++)
{
if(!f[i-1][j][p][q])continue;
//不干掉
if(a[i]>=a[id[i-1][j]])//钦定多个最大值只考虑最右边的
{
if(!mp[i].count(i))mp[i][i]=++tot[i],id[i][tot[i]]=i;
Add(f[i][mp[i][i]][p][q],f[i-1][j][p][q]);
}
else
{
if(!mp[i].count(id[i-1][j]))mp[i][id[i-1][j]]=++tot[i],id[i][tot[i]]=id[i-1][j];
Add(f[i][mp[i][id[i-1][j]]][p][(q+a[id[i-1][j]]-a[i])%2],f[i-1][j][p][q]);
}
//干掉
if(!mp[i].count(id[i-1][j]))mp[i][id[i-1][j]]=++tot[i],id[i][tot[i]]=id[i-1][j];
Add(f[i][mp[i][id[i-1][j]]][p+1][(q+a[id[i-1][j]])%2],f[i-1][j][p][q]);
}
}
}
}
g[n+1][1][0][0]=1;tot2[n+1]=1;
for(int i=n;i>=1;i--)
{
for(int j=1;j<=tot2[i+1];j++)
{
for(int p=0;p<=k;p++)
{
for(int q=0;q<=1;q++)
{
if(!g[i+1][j][p][q])continue;
//不干掉
if(a[i]>a[id2[i+1][j]])//钦定多个最大值只考虑最右边的
{
if(!mp2[i].count(i))mp2[i][i]=++tot2[i],id2[i][tot2[i]]=i;
Add(g[i][mp2[i][i]][p][q],g[i+1][j][p][q]);
}
else
{
if(!mp2[i].count(id2[i+1][j]))mp2[i][id2[i+1][j]]=++tot2[i],id2[i][tot2[i]]=id2[i+1][j];
Add(g[i][mp2[i][id2[i+1][j]]][p][(q+a[id2[i+1][j]]-a[i])%2],g[i+1][j][p][q]);
}
//干掉
if(!mp2[i].count(id2[i+1][j]))mp2[i][id2[i+1][j]]=++tot2[i],id2[i][tot2[i]]=id2[i+1][j];
Add(g[i][mp2[i][id2[i+1][j]]][p+1][(q+a[id2[i+1][j]])%2],g[i+1][j][p][q]);
}
}
}
}
for(int i=1;i<=n;i++)
{
if(!mp[i][i]||!mp2[i][i])continue;
int x=mp[i][i],y=mp2[i][i];
for(int j=0;j<=k;j++)
{
for(int p=0;p<2;p++)
{
Add(ans,1ll*f[i][x][j][p]*g[i][y][k-j][(2-p)%2]%mod);
}
}
}
cout<<ans;
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 11500kb
input:
20 10 17555697 225663153 267317961 109938115 578806141 659739421 597281665 103951030 285251051 66543...
output:
92314
result:
ok 1 number(s): "92314"
Test #2:
score: 10
Accepted
time: 24ms
memory: 173772kb
input:
20000 0 1447384 235371887 294560601 544621393 134982757 130696357 35748139 445921103 333479259 46356...
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 10
Accepted
time: 8ms
memory: 11956kb
input:
200 25 89405029 287841877 279147241 435182157 291231117 583624158 124125093 54923855 62173677 513305...
output:
420252466
result:
ok 1 number(s): "420252466"
Test #4:
score: 10
Accepted
time: 11ms
memory: 11952kb
input:
200 25 162098041 280130852 358612462 669241371 668611901 349053517 320595801 9356986 618973861 25689...
output:
883879813
result:
ok 1 number(s): "883879813"
Test #5:
score: 10
Accepted
time: 14ms
memory: 11952kb
input:
200 25 493903079 7288021 24327301 452516569 431951051 380381122 434128029 2483206 369058649 25886995...
output:
938347802
result:
ok 1 number(s): "938347802"
Test #6:
score: 10
Accepted
time: 56ms
memory: 23924kb
input:
1000 25 53675497 34703857 313369933 338081551 640372541 826017 852172048 11684239 570907231 15305318...
output:
220588771
result:
ok 1 number(s): "220588771"
Test #7:
score: 10
Accepted
time: 43ms
memory: 23920kb
input:
1000 25 585518166 289776964 22499577 79354617 868796353 116628083 88604314 51980500 92341116 4088509...
output:
207083490
result:
ok 1 number(s): "207083490"
Test #8:
score: 10
Accepted
time: 1191ms
memory: 423428kb
input:
25000 25 40306211 14787586 603428261 114843202 281743995 94890062 11251486 134541699 151076551 81962...
output:
706405307
result:
ok 1 number(s): "706405307"
Test #9:
score: 10
Accepted
time: 1186ms
memory: 423424kb
input:
25000 25 5913979 64575752 351952756 379776557 45242326 182872419 150007411 24063937 123538621 134891...
output:
694164021
result:
ok 1 number(s): "694164021"
Test #10:
score: 10
Accepted
time: 1223ms
memory: 423428kb
input:
25000 25 20176450 442815539 515507510 119624479 64047196 431741587 28989112 585526096 43950731 36846...
output:
473111641
result:
ok 1 number(s): "473111641"
Extra Test:
score: 0
Extra Test Passed