poj 1564 Sum It Up
来源:互联网 发布:ipad翻墙用什么软件 编辑:程序博客网 时间:2024/05/17 08:38
原题链接:http://poj.org/problem?id=1564
dfs。。
#include<algorithm>#include<iostream>#include<cstdlib>#include<cstring>#include<cstdio>#include<vector>#include<queue>#include<set>using std::set;using std::sort;using std::pair;using std::swap;using std::queue;using std::multiset;#define pb(e) push_back(e)#define sz(c) (int)(c).size()#define mp(a, b) make_pair(a, b)#define all(c) (c).begin(), (c).end()#define iter(c) decltype((c).begin())#define cls(arr, val) memset(arr, val, sizeof(arr))#define cpresent(c, e) (find(all(c), (e)) != (c).end())#define rep(i, n) for(int i = 0; i < (int)n; i++)#define tr(c, i) for(iter(c) i = (c).begin(); i != (c).end(); ++i)const int N = 1010;const int INF = 0x3f3f3f3f;typedef unsigned long long ull;bool f;int n, tot, tar, A[N], B[N];void dfs(int cur, int ret, int k) { if (ret == tar) { f = true; for (int i = 0; i < k; i++) { if (!i) printf("%d", B[i]); else printf("+%d", B[i]); } putchar('\n'); return; } for (int i = cur; i < n; i++) { if (i == cur || A[i] != A[i - 1]) { // 判重 B[k] = A[i]; dfs(i + 1, ret + A[i], k + 1); } }}int main() {#ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w+", stdout);#endif while (~scanf("%d %d", &tar, &n), n) { f = false; rep(i, n) scanf("%d", &A[i]); printf("Sums of %d:\n", tar); dfs(0, 0, 0); if (!f) { puts("NONE"); continue; } } return 0;}
1 0
- POJ 1564 - Sum It Up
- poj 1564 Sum It Up
- poj 1564 Sum It Up
- POJ 1564 Sum It Up
- POJ-1564-Sum It Up
- poj 1564 Sum It Up
- POJ 1564 Sum It Up
- POJ 1564 Sum It Up
- POJ 1564 Sum It Up
- poj 1564 Sum It Up
- Poj 1564 Sum It Up
- poj 1564 Sum It Up
- Poj Sum It Up
- poj sum it up
- poj sum it up
- POJ 1564 Sum It Up dfs
- poj 1564 Sum It Up -- DFS 递归
- POJ 1564 Sum It Up(DFS)
- 软件测试缺陷报告的5c标准
- 网络必须首先了解的基本知识
- JAVA中的多线程
- 怎样用cmd命令查看系统信息
- Swift 学习笔记(三)删除 Main.storyboard 和 LaunchScreen.storyboard
- poj 1564 Sum It Up
- E哥的Git教程(二)基础命令
- 通过JMS监听Oracle AQ,在数据库变化时触发执行Java程序
- Linux一些命令总结
- RecyclerView的基本使用(2)
- 五笔字根口诀
- iOS开发——RegressionBug和RegressionTest浅析
- C#语言特性
- 最近笔记