Yet Another Multiple Problem

本文探讨了在特定约束条件下生成数序列的问题,通过输入数值和条件,算法能够输出符合条件的序列,或在不存在时给出提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:

#include <stdio.h>
#include <string.h>
int p[10010],a[11],q[10010],f[10010];
int n,m,bg,ed;
void ss(int x)
{
	if (p[x]) ss(p[x]);
	putchar(f[x]+48);
}
void ff()
{
	int i;
	bg=ed=0;
	for(i=1;i<10;i++) 
		if(i%n==0&&!a[i])
		{
			printf("%d\n",i);
			return;
		} 
	for (i=1;i<10;i++)
		if (!a[i] && p[i % n]==-1)
		{
			q[ed++]=i%n;
			p[i%n]=0;
			f[i%n]=i;
		}
	while (bg<ed)
	{
		int u=q[bg++];
		for (i=0;i<10;i++)
			if(!a[i])
			{
				int v=(u*10+i)%n;
				if (v==0)
				{
					ss(u);
					printf("%d\n",i);
					return;
				}
				if (p[v]==-1) 
				{
					q[ed++]=v;
					p[v]=u;
					f[v]=i;
				}
			} 
	}
	puts("-1");
}
int main()
{
	int t=0,l;
	while (~scanf("%d",&n))
	{
		scanf("%d",&m);
		memset(p,-1,sizeof(p));
		memset(a,0,sizeof(a));
		for (int i=1;i<=m;i++)
		{
			scanf("%d",&l);
			a[l]=1;
		}
		printf("Case %d: ",++t);
		ff();
	} 
	return 0;
} 




acceptable to discuss approaches with other students, but you should not be looking at another student'swork while preparing your own. Question 1 Solve the following Integer Problem using the Branch & Bound algorithm Maximize +2w s.t. +3 w A +2w +10x +4y +6x +4x +3x +5V +7y -2y 68 政 170 w,x,y >= 0 and INTEGERRemember that although the original problem is integer, you are solving linear relaxations at each node ofthe algorithm (each problem you solve is a linear program with continuous variables). You will need multiple branches to solve this problem. If there are two or more fractional variables tobranch on, choose one arbitrarily (your choices might be difierent than a class-mates, and you will geldifferent answers as you go). This problem is tedious to solve to optimality. It is meant to show how inefficient branch and bound carbe, and why we learn about better algorithms. Because of that:If you haven’t found the optimal solution yet, you can stop after solving 10 subproblems Then report your results so far. Do you have a candidate solution? What bounds have you found on the obiective function value of the optimal solution? (do yotknow what z can be at most. and at least?)Which branch(es) do you still need to explore if you haven't found the optimal solution? e Or, if you think you found the optimal solution: Report the optimal solutioneIf you fathomed some branches, explain why you know you don't need to explore furtheiSolve it in Python using Gurobipy. All ofvour variables must be set to GRB.CONTINUOUS. Your scripcan be 'manual': vou can add and remove specific / hardcoded branches without writing code that coulcaccept any input. It is challenging to automate the script, and certainly not expected.
最新发布
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值