Memory Exceeded
Code
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[5005][5005];
ll n,k;
ll mod=1e9+7;
ll v[5004];
ll ok(ll i,ll j)
{
if(i>=n || j<k)
return 0;
if(dp[i][j]!=-1)
return dp[i][j];
ll op=0;
op=(op+ok(i+1,j))%mod;
if(v[i]==1)
op=(op+(((j-1)>=k)+ok(i+1,j-1)))%mod;
else
op=(op+((j>=k)+ok(i+1,j)))%mod;
return dp[i][j]=op;
}
int main()
{
ll tc;
cin>>tc;
while(tc--)
{
cin>>n>>k;
ll s=0;
for(int i=0;i<n;i++){
cin>>v[i];
s+=v[i];
}
if(s<k)
cout<<0<<endl;
else
{
for(int i=0;i<=n;i++) for(int j=0;j<=s;j++)
dp[i][j]=-1;
ll op=ok(0,s)%mod;
cout<<op<<endl;
}
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1093 Number of Ways (Easy version)
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-10-12 10:59:32
- Judged At
- 2024-11-11 02:37:34
- Judged By
- Score
- 20
- Total Time
- ≥965ms
- Peak Memory
- ≥128.016 MiB