NC200532(装货物 )

感受

思路






图片说明

#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;
}
全部评论

相关推荐

06-27 18:53
门头沟学院 Java
这样才知道自己不适合搞代码,考公去咯
只爱喝白开水:我也发现不适合搞代码,打算转非技术方向了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务