HDU 1455
来源:互联网 发布:js和php文件怎么运行 编辑:程序博客网 时间:2024/06/05 03:05
Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10645 Accepted Submission(s): 3206
Problem Description
George took sticks of the same length and cut them randomly until all parts became at most 50 units long. Now he wants to return sticks to the original state, but he forgot how many sticks he had originally and how long they were originally. Please help him and design a program which computes the smallest possible original length of those sticks. All lengths expressed in units are integers greater than zero.
Input
The input contains blocks of 2 lines. The first line contains the number of sticks parts after cutting, there are at most 64 sticks. The second line contains the lengths of those parts separated by the space. The last line of the file contains zero.
Output
The output file contains the smallest possible length of original sticks, one per line.
Sample Input
9
5 2 1 5 2 1 5 2 1
4
1 2 3 4
0
Sample Output
6
5
Source
ACM暑期集训队练习赛(七)
Recommend
lcy
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#define maxn 100030using namespace std;int vis[maxn];int len[maxn];int n;int sum;int ans;bool cmp(int x,int r){ return x>r;}bool dfs(int l, int num,int pos,int aim){ if(num==aim)return true; if(l==sum/aim)return dfs(0,num+1,0,aim); for(int i=pos;i<n;i++) { if(!vis[i]&&l+len[i]<=sum/aim) { vis[i]=1; if(dfs(l+len[i],num,i+1,aim))return true; vis[i]=0; if(l==0)return false; while(i+1<n&&len[i+1]==len[i])i++; } } return false;}int main(){ while(scanf("%d",&n)!=EOF) { if(n==0)break; sum=0; int ans=0; int maxnum=0; memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) { scanf("%d",&len[i]); sum+=len[i]; maxnum=max(maxnum,len[i]); } sort(len,len+n); for(int i=1;i<=sum;i++) { if(sum%i==0) { memset(vis,0,sizeof(vis)); if(dfs(0,0,0,sum/i)) { ans=i; break; } } } printf("%d\n",ans); } return 0;}
- HDU 1455
- HDU 1455
- hdu 1455 hdu 1455 Sticks
- HDU 1455 Sticks
- Hdu 1455 Sticks
- hdu 1455 Sticks
- HDU 1455 Sticks
- hdu 1455 Sticks
- hdu 1455 Sticks
- HDU 1455 Sticks
- 【DFS】hdu 1455 Sticks
- Sticks hdu 1455
- hdu 1455 sticks
- hdu 1455 搜索经典
- HDU 1455 Sticks
- HDU 1455 Sticks
- HDU 1455 Sticks
- HDU 1455 Sticks
- java中的数组简述
- Apache Spark 2.2.0 中文文档
- Kinect人物模型大小自动适配背景人物
- 网络抓包工具
- 我在eclipse中启动Tomcat8.5之后,运行项目下的JSP文件,总是报404错误,但是访问http://localhost:8080/地址却可以正常访问
- HDU 1455
- Spring Mvc-入门案例
- Android播放本地视频音频
- 定时器解决IE9中propertychange和input事件在拖拽、剪切、删除时无法触发
- Tomcat 7.0在Eclipse下安装与部署(下)
- SJXXX串口扩展芯片 UART(1) to UART(4)
- new/delete和malloc/free的区别
- abap对采购订单强制置为”交货已完成“状态(BAPI_PO_CHANGE、BAPI_PO_RELEASE、BAPI_PO_RESET_RELEASE)
- std::map error: implicit instantiation of undefined template 不能识别std::map迭代器指针