QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#621023#5303. No Bug No GamesazhiCompile Error//C++201.9kb2024-10-08 00:17:522024-10-08 00:17:52

Judging History

你现在查看的是最新测评结果

  • [2024-10-08 00:17:52]
  • 评测
  • [2024-10-08 00:17:52]
  • 提交

answer

// author:  jieda
// file:	cpp
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
# define fi first
# define se second
# define all(x) x.begin(),x.end()
# define stst stringstream
# define pb push_back
# define pf push_front
# define pp push
# define lowbit(x) (x)&(-x)
# define fa(i,op,n) for (int i = op; i <= n; i++)
# define fb(j,op,n) for (ll j = op; j >= n; j--)
# define fg(i,op,n) for (ll i = op; i != n; i = ne[i])
int dx[4] = {-1,0,1,0},dy[4] = {0,1,0,-1};
typedef unsigned long long  ull;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const ll N = 3e3+15,INF = 0x3f3f3f3f,mod = 1e9+7;
const ll MOD = 212370440130137957ll;//hash(hight)
const int base = 131;
const double eps = 1e-3;
const int seed=10086,mo=1e6+7; //hash(lower)
int prime = 233317;
ll dp[2][N][N];
void solve(){
	int n,k;cin>>n>>k;
	vector<vector<int>> w(n+1,vector<int>(15));
	vector<int> p(n+1),pre(n+1);
	fa(i,1,n) {
		cin>>p[i];
		pre[i] = pre[i-1]+p[i];
		fa(j,1,p[i]) cin>>w[i][j];
	}
	if(pre[n]<k){
		ll res = 0;
		for(int i = 1;i<=n;i++){
			res += w[i][p[i]];
		}
		cout<<res<<'\n';
		return ;
	}
	memset(f,-1e18,sizeof f);
	dp[0][0][0] = dp[1][n+1][0] = 0;
	for(int i = 1;i<=n;i++){
		for(int j = k;j>=p[i];j--){
			dp[0][i][j] = max(dp[0][i-1][j-p[i]]+w[i][p[i]],dp[0][i-1][j]);
		}
	} 
	for(int i = n;i>=1;i--){
		for(int j= k;j>=p[i];j--){
			dp[1][i][j] = max(dp[1][i+1][j-p[i]]+w[i][p[i]],dp[1][i+1][j]);
		}
	}
	ll ans = 0;
	for(int i= 1;i<=n;i++){
		for(int j = 1;j<=p[i]&&j<=k;j++){
			int res = k-j;
			for(int l = 0;l<=res;l++){
				int r = res - l;
				ans = max(ans,dp[0][i-1][l]+dp[1][i+1][r]+w[i][j]);
			}
		}
	}
	cout<<ans<<'\n';
}

int main()
{
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t = 1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
/*

*/

Details

answer.code: In function ‘void solve()’:
answer.code:47:16: error: ‘f’ was not declared in this scope
   47 |         memset(f,-1e18,sizeof f);
      |                ^