QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97415#4377. Backpack3360550356WA 204ms5684kbC++141.8kb2023-04-16 19:03:162023-04-16 19:03:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-16 19:03:18]
  • 评测
  • 测评结果:WA
  • 用时:204ms
  • 内存:5684kb
  • [2023-04-16 19:03:16]
  • 提交

answer

#include<bits/stdc++.h>
#define endl '\n'
#define int long long 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
const int N = 3e5+10;
const int M = 1e3 + 100;
const int mod = 1e9+7;
const int INF=1e9;
const double PI=acos(-1);
const double eps=1e-10;

//bitset优化背包dp 
int v[N],w[N];
bitset<M> dp[M];	//前i个物品中,异或和为j,总体积为k的方案是否存在 
bitset<M> t[M];		//临时 
void solve(){
	
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=1024;i++)dp[i].reset();
	for(int i=1;i<=n;i++){
		cin>>v[i]>>w[i];
	} 
	
	dp[0][0]=1;
	
	//第一维压掉 
	for(int i=1;i<=n;i++){ 
	
		for(int j=0;j<=1024;j++){
			t[j]=dp[j];
			t[j]<<=v[i];		//左移v[i]就是将原方案加k后的方案 
		} 
		
		//转移 
		for(int j=0;j<=1024;j++){
			dp[j]=dp[j]|t[j^w[i]];
		} 
	} 
	
	int ans=-1;
	for(int i=1024;i>=0;i--){
		if(dp[i][m]){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	
}
signed main() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(0);
	int T=1;
	cin>>T;
	while(T--) {
		solve();
	}
}

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃        ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 204ms
memory: 5684kb

input:

10
1023 401
179 441
416 951
420 984
1013 984
683 914
407 984
96 523
374 190
974 190
739 441
518 523
194 984
415 523
149 441
235 984
809 441
469 441
436 919
437 919
7 919
818 984
962 190
37 919
371 523
417 914
431 914
213 190
340 441
254 919
223 951
123 190
339 951
322 441
218 441
284 919
533 190
187...

output:

1024
1024
1024
1024
1024
1024
1024
1024
1024
577

result:

wrong answer 1st lines differ - expected: '1021', found: '1024'