QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97422#4377. Backpack3360550356AC ✓208ms3640kbC++141.8kb2023-04-16 19:09:092023-04-16 19:09:13

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:09:13]
  • 评测
  • 测评结果:AC
  • 用时:208ms
  • 内存:3640kb
  • [2023-04-16 19:09:09]
  • 提交

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 = 1e3+100;
const int M = 2e6 + 10;
const int mod = 1e9+7;
const int INF=1e9;
const double PI=acos(-1);
const double eps=1e-10;

bitset<N> f[N],temp[N];
void solve(){
	int t;
	cin>>t;
	while(t--){
		int n,m,x,y;
		cin>>n>>m;
		for(int i=0;i<N;i++){
			f[i].reset();
		}
		f[0][0]=1;
		
		long long ans=-1;
		for(int i=1;i<=n;i++){
			cin>>x>>y;
			for(int j=0;j<=1024;j++){
				temp[j]=f[j];		//保存上一状态
				temp[j]<<=x;		//体积加上x 
			}
			for(int j=0;j<1024;j++){
				f[j]=f[j]|temp[j^y];
			}	
			//相当于f[i][j][V]=f[i-1][j][V]|f[i-1][j^y][V-x] 		//就是当前物品选或上不选 
		}
		
		for(int i=1;i<=1024;i++){
			if(f[i][m])ans=i;//如果存在异或和为i,体积为m,那么记录该答案;
		}
		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: 100
Accepted
time: 208ms
memory: 3640kb

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:

1021
1011
-1
1023
1023
1023
1023
1023
1023
513

result:

ok 10 lines