究极玄学
查看原帖
究极玄学
1026751
Lawrenceling楼主2025/1/21 21:13

rt,不是标题党。

#include<bits/stdc++.h>
using namespace std;

const int N=1e2+10;//here
const int INF=2e9;
int a[N],n,k,dp[N];
int ans[N],xans;

void DFS(int id)
{
	if(id<=k)
	{
		for(int i=a[id-1]+1;i<=a[id-1]*n+1;++i)
		{
			a[id]=i;
			DFS(id+1);
		}
	}
	else if(id>k)
	{
		int maxx=0;
		memset(dp,0,sizeof(dp));
		while(dp[maxx]<=n)
		{
			maxx++;
			dp[maxx]=INF;
			for(int i=1;i<=k;++i)
			{
				if(maxx-a[i]<0)break;
				dp[maxx]=min(dp[maxx],dp[maxx-a[i]]+1); 
			}
		}
		maxx--;
		if(maxx>xans)
		{
			for(int i=1;i<=k;++i)
			{
				ans[i]=a[i];
			}
			xans=maxx;
		}
	}
}

signed main()
{
	scanf("%d%d",&n,&k);
	a[1]=1;
	DFS(2);
	for(int i=1;i<=k;++i)printf("%d ",ans[i]);
	printf("%d",xans);
	return 0;
} 

上述的一份代码,是无法通过的。

但是实测第二行的结果完全正确??

说明 ansans 数组被改了,但是输出最后一次修改也完全与答案一样??

比如 5 5 ,上述代码跑出了 4 5 5 4 3 \nMAX=126 的结果。

还有玄学。仅仅是将 const int N=1e2+10; 修改成 const int N=1e3+10; 就过了????

在线求解答(晕

2025/1/21 21:13
加载中...