建议加强数据
  • 板块P1537 弹珠
  • 楼主Lyco_Reco
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/4/9 11:41
  • 上次更新2024/4/9 11:42:50
查看原帖
建议加强数据
1015670
Lyco_Reco楼主2024/4/9 11:41

如题,O(n2k)O(n^2k) 暴力可过。

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <deque>
#include <queue>
#include <iomanip>
#include <map>
#include <unordered_map>
using namespace std;
#define int long long
#define inf 0x7f7f7f7f
#define maxn 120010
int ca,n,a[maxn],b[7],s[maxn],tot;
bool dp[maxn];
namespace Main{
	int rd(){
		int x=0,f=1;
		char ch=getchar();
		while(ch<'0'||ch>'9'){
			if(ch=='-'){
				f=-1;
			}
			ch=getchar();
		}
		while(ch>='0'&&ch<='9'){
			x=x*10+ch-'0';
			ch=getchar();
		}
		return x*f;
	}
	void wrt(int x){
		int y=10,len=1;
		if(x<0){
			x=-x;
			putchar('-');
		}
		while(y<=x){
			len++;
			y*=10;
		}
		while(len--){
			y/=10;
			putchar(x/y+'0');
			x%=y;
		}
	}
	void MAIN(){
		while(true){
			ca++;
			bool ed=true;
			tot=0;
			for(int i=1;i<=6;i++){
				cin>>b[i];
				if(b[i]!=0){
					ed=false;
				}
				for(int j=1;j<=b[i];j++){
					a[++tot]=i;
					s[tot]=s[tot-1]+a[tot];
				}
			}
			if(ed){
				break;
			}
			dp[0]=1;
			fill(dp+1,dp+s[tot]+1,0);
			for(int i=1;i<=tot;i++){
				for(int j=a[i];j<=s[i];j++){
					dp[j]|=dp[j-a[i]];
				}
			}
			cout<<"Collection #"<<ca<<":\n";
			if(s[tot]&1){
				cout<<"Can't be divided.\n";
			}
			else{
				if(dp[s[tot]>>1]){
					cout<<"Can be divided.\n";
				}
				else{
					cout<<"Can't be divided.\n";
				}
			}
			cout<<'\n';
		}
	}
}
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	Main::MAIN();
	return 0;
}

2024/4/9 11:41
加载中...