pat 1053
来源:互联网 发布:通达信敢死队资金源码 编辑:程序博客网 时间:2024/05/21 02:36
简单回溯,其实还可以再剪枝的,数据太小,没有超时,也就懒得改了o(╯□╰)o
#include<stdio.h>#include<vector>#include<algorithm>#define SIZE 100using namespace std;struct tree{ int index; int weight; bool flag;} t[SIZE];vector <int> node[SIZE];vector<int>p;bool cmp(const int &a, const int &b){ return t[a].weight > t[b].weight;}void FindPath(int s, int weight,int sum){ sum += t[s].weight; t[s].flag = true; p.push_back(t[s].weight); int i; if (sum == weight&&!node[s].size()){ for (i = 0; i < p.size(); i++){ printf("%d",p[i]); if (i == p.size() - 1) putchar('\n'); else putchar(' '); } p.pop_back(); return; } sort(node[s].begin(), node[s].end(),cmp); for (i = 0; i < node[s].size(); i++) FindPath(node[s][i], weight, sum); p.pop_back();}int main(){ freopen("1.in", "r", stdin); int noneleaf, nodes, weight; scanf("%d%d%d", &nodes, &noneleaf, &weight); int i; for (i = 0; i < nodes; i++){ scanf("%d", &t[i].weight); t[i].flag = false; t[i].index = i; } int index, j, numofkids, kids; for (i = 0; i < noneleaf; i++){ scanf("%d%d", &index, &numofkids); for (j = 0; j < numofkids; j++){ scanf("%d", &kids); node[index].push_back(kids); } } FindPath(0, weight,0); return 0;}
0 0
- pat 1053
- pat 1053
- Pat 1053
- PAT 1053
- PAT 1050-1053
- pat-advanced(1050-1053)
- PAT(甲级)1053
- 浙大PAT甲级 1053
- PAT乙级1053
- pat-bl-1053
- PAT甲级1053
- PAT basic 1053
- pat
- 【PAT】
- PAT
- PAT
- PAT
- PAT
- 自己动手写编译器、链接器一书作者自序
- 使用crontab自动执行php文件
- 用VC开发串口通信dll控件
- 最大连续子序列和(6种解决方法)
- HeberNate入门(一)
- pat 1053
- 客户表结构SQL语句
- Screen
- RDLC报表中添加链接
- Log工具类
- 学习资料
- 九度 题目1453:Greedy Tino
- Codeforces 336D Vasily the Bear and Beautiful Strings 组合数学
- Android 中将字符串文字内容复制到系统剪贴板并从剪贴板拿出来显示