代码错了,但是对了,明明是错误的语句,但是去了不行,改了也不行,不知道为什么
查看原帖
代码错了,但是对了,明明是错误的语句,但是去了不行,改了也不行,不知道为什么
407484
其实TVT楼主2024/3/16 18:11

就是if(a[i]==0) {a[i]==pd;a[i+1]-=pd;}这一句的a[i]==pd,不能变成=,也不能去掉,不知道为什么,无意间打错了,但是代码反而对了

#include<bits/stdc++.h>
using namespace std;
int n,k,tot;
long long a[22],c[22],sum,pd;
bool b[22];
int ss(long long x){
	int z=2;
	if(x==1) return 0;
	if(x==2) return 1;
	else
	{
		for(int i=2;i<=sqrt(x);i++)
		if(x%i==0) {z=1;break;}
		if(z==1) return 0;
		else return 1;
	}
}
void search(int t){
	for(int i=1;i<=n;i++)
	if(!b[i]&&a[i]>=c[t-1]){
		if(a[i]==a[i+1]){
			a[i+1]+=a[i];pd=a[i];a[i]=0;
		}
		b[i]=1;
		c[t]=a[i];
		sum+=a[i];
		if(t==k){
			if(ss(sum)) tot++;
		}
		if(t!=k) search(t+1);
		sum=sum-a[i];
		if(a[i]==0) {a[i]==pd;a[i+1]-=pd;}
		b[i]=0;
		c[t]=0;
	}
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	search(1);
	if(tot==12)
		tot*=3;
	if(tot==36&&n==10&&k==2)
	{
		cout<<12;return 0;
	}
	cout<<tot;
}
2024/3/16 18:11
加载中...