文章

30

粉丝

0

获赞

17

访问

3.6k

头像
简单背包问题 题解:
P1035
发布于2026年2月12日 20:39
阅读数 102

25正确率DFS+剪纸

#include <iostream>
#include <map>
#include <cctype>   // for isalpha, tolower
#include <string>
#include<algorithm>
#include<stack> 
#include<stdlib.h> //C打印库函数 
#include<climits>//climits中的最大最小值
#include<vector> 
#include<queue>
#include<set> 
using namespace std;
int n,s,temp;
vector<int> w;

bool dfs(int i, int remaining) {
    if (remaining == 0) return true;           // 找到了
    if (i >= n || remaining < 0) return false; // 越界或超了
    //    剪支 
    // 选 w[i]
    if (dfs(i + 1, remaining - w[i])) 
        return true;

    // 不选 w[i]
    if (dfs(i + 1, remaining))
        return true;

    return false;
}
int main() {
    
    cin>&g...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发