This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int dp[20005][55];
int cost[4005][4005];
int n,t,s;
int val[20005];
bool have[55][20005];
bool bad[55];
int mycost[55];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>t>>s;
for(int i=1;i<=t;i++)
cin>>val[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=t;j++)
{
char c;
cin>>c;
have[i][j]=c-'0';
}
for(int i=1;i<=t;i++)
{
for(int j=1;j<=n;j++)
{
bad[j]=0;
mycost[j]=0;
}
int cur=0;
for(int j=i;j<=t;j++)
{
for(int k=1;k<=n;k++)
if(!bad[k])
{
if(have[k][j])
{
cur+=val[j];
mycost[k]+=val[j];
}
else
{
bad[k]=1;
cur-=mycost[k];
mycost[k]=0;
}
}
cost[i][j]=cur;
}
}
dp[0][0]=0;
for(int i=1;i<=s;i++)
dp[0][i]=2e9;
for(int i=1;i<=t;i++)
{
dp[i][0]=2e9;
for(int j=1;j<=s;j++)
{
dp[i][j]=2e9;
for(int k=i-1;k>=0;k--)
dp[i][j]=min(dp[i][j],dp[k][j-1]+cost[k+1][i]);
}
}
for(int i=1;i<=s;i++)
cout<<dp[t][i]<<'\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |