QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#395524#4377. BackpackCMingAC ✓151ms3696kbC++141016b2024-04-21 15:56:182024-04-21 15:56:19

Judging History

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

  • [2024-04-21 15:56:19]
  • 评测
  • 测评结果:AC
  • 用时:151ms
  • 内存:3696kb
  • [2024-04-21 15:56:18]
  • 提交

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++)
	{
		// cout << "i = " << i << "---------\n";
        for(int k = 0; k < N; k++)
		{
        	//for(int j = m; j >= v[i]; j--)
                f[k] |= f[k ^ w[i]] << v[i];
			// cout << k << ":" << f[k] << "\n";
		}

	}


    for(int i = N - 1; i >= 0; i--)
        if(f[i][m])
        {
            cout << i << '\n';
            return;
        }

	cout << "-1\n";
}

signed main()
{
	//freopen("D:\\VSC\\00\\in.txt","rt",stdin);
	//freopen("D:\\VSC\\00\\out.txt","wt",stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t--)
	{
		#ifdef BOOL
		if(solve()) cout << "YES\n";
		else cout << "NO\n";
		#else
		solve();
		#endif
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 151ms
memory: 3696kb

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