子集和問題——回溯法

給定一個正整數集合X={x1,x2,…,xn}和一個正整數y,設計回溯算法,求集合X的一個子集Y,使得Y中元素之和等於y。ios #include<iostream> using namespace std; #define NUM 10000 int n; int c; int cw; int bestw; int w[NUM]; int x[NUM]; int r; bool flag;
相關文章
相關標籤/搜索