QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56359#4377. BackpackqinjianbinAC ✓212ms3784kbC++11657b2022-10-18 22:06:062022-10-18 22:06:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-18 22:06:09]
  • 评测
  • 测评结果:AC
  • 用时:212ms
  • 内存:3784kb
  • [2022-10-18 22:06:06]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define _for(i, a, b) for(int i = (a); i <= (b); i++)
using namespace std;

const int N = (1 << 10) + 10;
bitset<N> f[N];
int n, m, w[N], v[N];

int main()
{
	int T; scanf("%d", &T);
	while(T--)
	{
		scanf("%d%d", &n, &m);
		_for(i, 1, n) scanf("%d%d", &v[i], &w[i]);

		rep(j, 0, 1 << 10)
			f[j].reset();

		f[0][0] = 1;
		_for(i, 1, n)
			rep(j, 0, 1 << 10)
				f[j] |= f[j ^ w[i]] << v[i];
		
		int ans = -1;
		for(int S = (1 << 10) - 1; S >= 0; S--)
			if(f[S][m])
			{
				ans = S;
				break;
			}
		printf("%d\n", ans);
	}

	return 0; 
} 

详细

Test #1:

score: 100
Accepted
time: 212ms
memory: 3784kb

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