文章标题
来源:互联网 发布:美图秀秀抠图软件下载 编辑:程序博客网 时间:2024/04/29 12:03
#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>#include<ctime>#define RG registerusing namespace std;int n,tail=0,num=0,maxx=-999999,sum=0,length,flag,minn=9999999;int bj[300000],stick[300000];inline int read(){ int s=0,k=1; char ch=getchar(); while(ch<'0'||ch>'9'&&ch!='-') ch=getchar(); if(ch=='-') k=-1,ch=getchar(); while(ch>='0'&&ch<='9') s=s*10+(ch-'0'),ch=getchar(); return s*k;}inline int comp(int a,int b){ return a>b;}inline void dfs(int current,int depth,int get_now){ if(depth==length) {current++;get_now=0;depth=0;}//当前找到一根木棍 if(current==num) {flag=1;return;}//答案符合要求 for(int i=get_now+1;i<=tail;i++) { if(!bj[i]) continue; if(depth+stick[i]>length) continue; if(stick[i]==stick[i-1]&&bj[i-1]==1) continue;//当前木棍与上一根长度相等,上一根不选,这一根也不选 bj[i]=false; dfs(current,depth+stick[i],i); if(flag) return; bj[i]=true; if(depth==0) return;//靠前面的木棍不能匹配成功,则后面也不能,答案不符合要求 } }int main(){ memset(bj,true,sizeof(bj)); n=read(); for(RG int i=1;i<=n;i++) { RG int zz=read(); if(zz<=50) stick[++tail]=zz,maxx=max(maxx,zz),sum+=zz; } sort(stick+1,stick+tail+1,comp);//排序方便剪枝 for(RG int i=maxx;i<=sum;i++) { if(sum%i==0) { flag=0; num=sum/i; length=i; dfs(0,0,0); } if(flag) {printf("%d\n",i);return 0;} }}
1 5
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 微软.NET年芳15:我在Azure上搭建Photon服务器(C#.NET)
- 30分钟概览Spark分布式计算引擎
- 登录型爬虫的写法
- python学习笔记3--dict和set
- 学习笔记——自定义Dialog
- 文章标题
- c语言HTTP服务器,超级简易版。
- 超强、超详细Redis入门教程
- 多线程的基本干概念
- 169. Majority Element
- iOS学习笔记-049.UITabBarController
- Reactive Programming with RxJava-Chapter4:Applying Reactive Programming to Existing Application(2)
- android gif
- 多线程CountDownLatch和Join