蓝桥杯每日打卡第五天

1.题目

2.代码

#include<bits/stdc++.h>

using namespace std;

int A,B,C;

struct node
{
	int staA,staB,staC;
};

vector<node> P;
set<int> res;

bool isInclude(node v)
{
	for(int i=0;i<P.size();i++)
	{
		node N=P[i];
		if(N.staA==v.staA&&N.staB==v.staB)
		{
			return true;
		}
	}
	P.push_back(v);
	return false;
}

void DFS(node n)
{
	if(isInclude(n)) return;
	if(n.staA==0) res.insert(n.staC);
	int mV;
	if(n.staA)
	{
		if(B!=n.staB)
		{
			mV=min(n.staA,(B-n.staB));
			node cn=n;
			cn.staA-=mV;
			cn.staB+=mV;
			DFS(cn);
		}
		if(C!=n.staC)
		{
			mV=min(n.staA,(C-n.staC));
			node cn=n;
			cn.staA-=mV;
			cn.staC+=mV;
			DFS(cn);
		}
	}
	if(n.staB)
	{
		if(A!=n.staA)
		{
			mV=min(n.staB,(A-n.staA));
			node cn=n;
			cn.staB-=mV;
			cn.staA+=mV;
			DFS(cn);
		}
		if(C!=n.staC)
		{
			mV=min(n.staB,(C-n.staC));
			node cn=n;
			cn.staB-=mV;
			cn.staC+=mV;
			DFS(cn);
		}
	}
	if(n.staC)
	{
		if(A!=n.staA)
		{
			mV=min(n.staC,(A-n.staA));
			node cn=n;
			cn.staC-=mV;
			cn.staA+=mV;
			DFS(cn);
		}
		if(B!=n.staB)
		{
			mV=min(n.staC,(B-n.staB));
			node cn=n;
			cn.staC-=mV;
			cn.staB+=mV;
			DFS(cn);
		}
	}
}

int main()
{
	
	scanf("%d%d%d",&A,&B,&C);
	node n;
	n.staA=0;n.staB=0;n.staC=C;
	DFS(n);
	for(auto it=res.begin();it!=res.end();it++)
	    printf("%d ",(*it));
	printf("\n");
	return 0;	
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值