我*,倒过来就行了?
查看原帖
我*,倒过来就行了?
520544
Phrvth楼主2023/8/21 14:42

关于这题的一个错解,但是他的程序和我的程序跑了0.5h左右的对拍没有问题!!

一般的错解是正着的,但是这位大佬把这个循环倒过来了,这是他的代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=15,M=1005;
ll dp[(1<<N)],n,m,a[M][M];
ll cal(ll st,ll a[])
{
	for(int i=1;i<=n;i++)
	{
		if(a[i]==1){
			if((1<<(i-1))&st)
			{
				st-=(1<<(i-1));
			}
		}
		if(a[i]==-1){
			st|=(1<<(i-1));
		}
	}
	return st;
}
int main()
{
//	freopen("cin.in", "r", stdin);
//	freopen("cout.out", "w", stdout);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		for(int j=n;j>=1;j--)
		{
			scanf("%lld",&a[i][j]);
		}
	}
	memset(dp,0x3f,sizeof(dp));
	dp[(1<<n)-1]=0;
	for(int st=(1<<n)-1;st>=0;st--)
	{
		for(int i=1;i<=m;i++)
		{
			ll t=dp[st];
			ll nt=cal(st,a[i]);
			dp[nt]=min(dp[st]+1,dp[nt]);
		}
	}
	if(dp[0]==dp[(1<<N)-1])cout<<-1;
	else cout<<dp[0];
	return 0;
}

请问一下有没有大佬告诉我原因

2023/8/21 14:42
加载中...