sumofsub
来源:互联网 发布:最有效的淘宝推广方式 编辑:程序博客网 时间:2024/06/15 17:53
#include <iostream>#include <cstdlib>#include <cstring>using namespace std;int x[256], w[256];int M, n;void print(int n){int i;for (i = 1; i <= n; i++){if (x[i]){cout << w[i] << ' ';}}cout << endl;}void sumofsub(int s, int k, int r){if (k > n)return;x[k] = 1;if (s + w[k] == M)print(k);else if (s + w[k] + w[k + 1] <= M)sumofsub(s + w[k], k + 1, r - w[k]);x[k] = 0;if (s + r - w[k] >= M && s + w[k + 1] <= M)sumofsub(s, k + 1, r - w[k]);}int main(){int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};int W = 0;int i;M = 20;n = sizeof(a) / sizeof(int);memset(w, 0, sizeof(w));for (i = 1; i <= n; i++){w[i] = a[i - 1];W += w[i];}sumofsub(0, 1, W);cin.get();return 0;}
0 0
- sumofsub
- Android Animation学习(六) View Animation介绍
- Android手机 Fildder真机抓包
- SMTP 服务器要求安全连接或客户端未通过身份验证的各个解决方案(C#)
- Xcode基本操作
- TCP连接
- sumofsub
- 归并排序(Merge Sort)
- 今日作息及食谱(7.2)
- All repo command
- 1:Commons BeanUtils组件简介
- Python中的高级数据结构
- There is no Action mapped fornamespace /xxx and action name xxx. - [unknown location]
- c#绘图
- APDU命令的结构和处理