#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
int N,M,S;
int weight[200]={0};
struct node
{
vector<int> child;
}cube[200];
vector<int> v;
void dfs(int id,int w)
{
if(w>S)
return;
if(cube[id].child.size()==0)//到叶子了return
{
if(w==S)
{
for(int i=0;i<v.size();i++)
{
printf("%d",v[i]);
if(i!=v.size()-1)
printf(" ");
}
printf("\n");
}
return;
}
for(int i=cube[id].child.size()-1;i>=0;i--)
{
v.push_back(weight[cube[id].child[i]]);
//printf("push: %d w:%d\n",weight[cube[id].child[i]],w+weight[cube[id].child[i]]);
dfs(cube[id].child[i],w+weight[cube[id].child[i]]);
v.pop_back();
}
return;
}
bool cmp(int a,int b)
{
return weight[a]<weight[b];
}
int main()
{
// freopen("in.txt","r",stdin);
scanf("%d %d %d",&N,&M,&S);
for(int i=0;i<N;i++)
{
scanf("%d",&weight[i]);
}
for(int i=0;i<M;i++)
{
int id;
int n;
scanf("%d %d",&id,&n);
vector<int> vt;
for(int j=0;j<n;j++)
{
int t;
scanf("%d",&t);
vt.push_back(t);
}
sort(vt.begin(),vt.end(),cmp);
for(int j=0;j<n;j++)
{
cube[id].child.push_back(vt[j]);
}
}
v.push_back(weight[0]);
dfs(0,weight[0]);
return 0;
}
1053. Path of Equal Weight (30)
最新推荐文章于 2022-04-13 00:26:50 发布