QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#395526#4377. BackpackCMingAC ✓169ms3692kbC++14633b2024-04-21 15:59:022024-04-21 15:59:03

Judging History

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

  • [2024-04-21 15:59:03]
  • 评测
  • 测评结果:AC
  • 用时:169ms
  • 内存:3692kb
  • [2024-04-21 15:59:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 1024;
void solve()
{
    int n, m; cin >> n >> m;
    vector<int> v(n + 1), w(n + 1);
    for(int i = 1; i <= n; i++) cin >> v[i] >> w[i];
    vector<bitset<N> > f(N);
    f[0][0] = 1;
    for(int i = 1; i <= n; i++)
        for(int k = 0; k < N; k++)
            f[k] |= f[k ^ w[i]] << v[i];
    for(int i = N - 1; i >= 0; i--)
        if(f[i][m])
        {
            cout << i << '\n';
            return;
        }
	cout << "-1\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t;
	cin >> t;
	while (t--)
		solve();
}

详细

Test #1:

score: 100
Accepted
time: 169ms
memory: 3692kb

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