感受
思路
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 10;
const ll mod = 998244353;
int n, x;
ll w, use[50], a[50];
bool ok;
bool cmp(ll b, ll c){
return b > c;
}
void dfs(int pos){
if(pos == n + 1) ok = true;
if(ok) return ;
for(int i = 1; i <= min(pos, x); i++){
if(use[i] + a[pos] > w) continue;
use[i] += a[pos];
dfs(pos + 1);
use[i] -= a[pos];
}
}
int main(){
int t;
scanf("%d", &t);
while(t--){
ok = false;
scanf("%d%d%lld", &n, &x, &w); x = min(x, n);
for(int i = 1; i <= n; i++) scanf("%lld", &a[i]), use[i] = 0;
sort(a + 1, a + n + 1, cmp);
dfs(1);
if(ok) puts("Yes");
else puts("No");
}
return 0;
}



京公网安备 11010502036488号