青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

oyjpArt ACM/ICPC算法程序設計空間

// I am new in programming, welcome to my blog
I am oyjpart(alpc12, 四城)
posts - 224, comments - 694, trackbacks - 0, articles - 6

PKU 1011 Sticks

Posted on 2006-11-30 00:34 oyjpart 閱讀(4048) 評論(15)  編輯 收藏 引用 所屬分類: ACM/ICPC或其他比賽
這道題作的我真的是悲喜交加阿。。。做完之后。。。長舒一口氣。。推薦大家去做!!!

Sticks
Time Limit:1000MS? Memory Limit:10000K
Total Submit:18973 Accepted:4421

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 should 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 















1。我從大到小搜索了哇 沒用。。。
2。我想 用預先得到所有可拼湊長度來HASH 發現太大...
3。然后我想對每個長棍分開搜索...
4。后來我又用記錄數目的方法搜 似乎更慢...
終于發現真正重要的剪枝!
1.當一個正好可以填滿的時候 就不用考慮比他小的去填了
2.一大段的第一個小段如果不成立直接返回到上一大段
這才是重要的剪枝
同時還有一個 要預防反復搜索同一關鍵碼 給出下面的測試數據
64
40 40 40 40 40 40 40 40 40 40 40 40 40
40 40 40 40 40 40 40 40 40 40 43 42 42
41 10 4 40 40 40 40 40 40 40 40 40 40
40 40 40 40 40 40 40 40 40 40 40 40 40
40 40 40 40 40 40 40 40 40 40 40 40
0
呵呵 其實AC的程序里面有一大部分都過不了這個數據!包括0MSAC的!

呵呵 過了之后 心情好啊~`哈哈
//Solution
//by optimistic
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int nss;
int ss[70];
int used[70];
int totss;
int maxss;
int len;
int cmp(const void * a, const void * b)
{
?return (*(int *)b) - (*(int *)a);
}
int search(int times, int rest, int pos)
{
?int flag = 0;
?if(rest == len) flag = 1; //第一種剪枝
?int i;
?if(times == totss/len) return 1;
?for(i = pos; i<nss; i++)
??if(!used[i])
??{
???if(rest == ss[i])
???{
????used[i] = 1;
????if(search(times+1, len, 0))?return 1;
????used[i] = 0;
??? ?return 0;????????????????????? //第二種剪枝???????????????????????????????????????????????????????????????????
???}
???else if(ss[i]<rest)
???{
????used[i] = 1;
????if(search(times, rest-ss[i], i+1)) return 1;
????used[i] = 0;
????if(flag) return 0;
????while(ss[i] == ss[i+1]) i++;
???}
???else if(flag) return 0;
??}
?return 0;
}
int main()
{
//?freopen("t.in", "r", stdin);
?int i;
?while(scanf("%d", &nss), nss>0)
?{
??memset(ss, 0, sizeof(ss));
??totss = maxss = 0;
??for(i=0; i<nss; i++)
??{
???scanf("%d", &ss[i]);
???totss += ss[i];
???if(ss[i]>maxss) maxss = ss[i];
??}
??qsort(ss, 70, sizeof(ss[0]), cmp);
??for(i=maxss; i<=totss; i++)
??{
???if(i==totss)
???{printf("%d\n", totss); break;}
???if(totss%i==0)
???{?????
????memset(used, 0, sizeof(used));
????len = i;

????if(search(1, len, 0)) {printf("%d\n", i); break;}
???}
??}
?}
?return 0;
}




Feedback

# re: PKU 1011 Sticks   回復  更多評論   

2007-04-13 23:40 by Jun Wang
if(search(1, len, 0)) {printf("%d\n", i); break;}
是不是要改成 if(search(0, len, 0)) {printf("%d\n", i); break;} ??

# re: PKU 1011 Sticks   回復  更多評論   

2007-07-22 19:28 by Typhoooooooooooooooooooooooooooooooooon
感謝你那兩個重要的剪枝哈

# re: PKU 1011 Sticks   回復  更多評論   

2007-10-24 11:00 by delguoqing
你上面這個測試數據的ouput是多少?

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-04 23:46 by mango
你測這個... 你的半天也出不來...
64
40 40 30 35 35 26 15 40 40 40 40 40 40 40 40 40 40 40 40 40 40

40 40 43 42 42 41 10 4 40 40 40 40 40 40 40 40 40 40 40 40 40

40 25 39 46 40 10 4 40 40 37 18 17 16 15 40 40 40 40 40 40 40

40

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-05 09:02 by oyjpart
的確啊,很強大的數據啊

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-05 18:42 by zoyi
答案是454~~可是我的程序居然是wa~5555555555

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-05 20:10 by oyjpart
哦?你怎么知道答案啊

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-06 19:43 by zoyi
我的程序跑出來的啊~~難道你懷疑我跑的是錯誤的???哈哈@oyjpart

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-07 12:49 by mango
哎......這個數據真變態...煩死了 呵呵

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-07 21:06 by oyjpart
哦。。。你過題了沒

# re: PKU 1011 Sticks   回復  更多評論   

2008-05-22 15:59 by zsong
我跑出454了,很快,不過也是wa

# re: PKU 1011 Sticks   回復  更多評論   

2008-08-12 20:45 by zjh777007
誰能告訴我
“一大段的第一個小段如果不成立直接返回到上一大段”
什么意思?

# re: PKU 1011 Sticks   回復  更多評論   

2008-08-12 20:53 by oyjpart
現在由一個當前情況S.
這個時候比如有一個大棍子,長度為20,現在嘗試在其中放入一個長度為5的小棍子。結果深搜得到的結果是不可行,則認為當前情況是無解的。
因為這個5長度的小棍子放不了這個大棍子,絕對放不了任何一根大棍子。

# re: PKU 1011 Sticks   回復  更多評論   

2008-11-30 11:29 by abc
#include<iostream>
#include<string>
#include<fstream>
#include<vector>
#include<ctime>
using namespace std;
fstream fin("e:\\office\\txt\\acmin.txt");
int l[65];
int s,t,min,sum=0,len;
int max2;
int count=0;
int c=0;
static int used[65];
int search(int leni, int s){
if(leni==0) return 100;
t=s;
int count=0;
while(l[t]>leni||used[t]){
t--;
if(t==0){
//break;
return 0;
}
}
used[t]=1;
count++;
if(l[t]<=leni){
int se=search(leni-l[t],s-1);

if(se>=100){
count+=(se-100);
//if((leni-l[t])!=0){
//if(count<s){
c=1;
for(int i=1;i<=s;i++)c*=used[i];
if(!c){
int sea=search(len,s-1);
if(sea>=100){
count+=(sea-100);
return count+100;
}/*else{
return 0;
}*/
//}
}
}
/*else{
return 0;
}*/
}
count+=100;
return count;
}
int main(){
cin>>s;
while(s){

max2=0;
sum=0;
count=0;
for(int i=0;i<65;i++)used[i]=0;
for(int i=1;i<=s;i++){
cin>>l[i];
if(l[i]>max2){
max2=l[i];
}
sum+=l[i];
}
for(int i=0;i<=s;i++){
for(int j=0;j<s-i;j++){
if(l[j]>l[j+1]){
int temp=l[j];
l[j]=l[j+1];
l[j+1]=temp;
}
}
}
cout<<"sum"<<sum<<endl;
for(int i=max2;i<=sum;i++){
len=i;

for(int j=0;j<65;j++)used[j]=0;
if(sum%i!=0)continue;

int k=search(i,s);

if(k>100){

if((k-100)==s){cout<<i<<endl;break;}
}else{
continue;
}
}
cin>>s;
}

}













# re: PKU 1011 Sticks   回復  更多評論   

2008-11-30 11:30 by abc
各位高手幫忙看一下上面的程序有什么錯誤,萬分感激!
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美日韩日韩| 免费观看30秒视频久久| 国产精品视频网| 欧美日韩直播| 国产精品福利久久久| 国产精品女同互慰在线看| 国产精品乱码久久久久久| 国产精品三级视频| 国产一区二区欧美| 在线观看国产精品网站| 亚洲精品日韩在线观看| 亚洲视频一区二区| 亚洲免费在线视频| 久久久久久电影| 亚洲电影免费在线| 亚洲国产欧美精品| 一本色道久久加勒比88综合| 亚洲欧美美女| 欧美成人精品一区二区| 欧美日韩精品系列| 国产一区二区三区的电影| 亚洲激情偷拍| 欧美一区二区三区视频在线| 另类春色校园亚洲| 9人人澡人人爽人人精品| 欧美在线1区| 欧美日韩中文字幕日韩欧美| 激情久久综艺| 欧美亚洲免费高清在线观看| 亚洲第一黄色| 久久国产精品久久久久久久久久| 欧美精品久久久久久| 韩日精品视频一区| 亚洲欧美成人网| 亚洲高清在线| 久久精品亚洲一区二区| 欧美性猛交xxxx乱大交蜜桃| 亚洲黑丝一区二区| 久久久av水蜜桃| 亚洲午夜国产一区99re久久| 欧美激情综合| 亚洲激情一区二区三区| 久久精品国产久精国产思思| 在线综合亚洲| 欧美日韩精品免费观看视一区二区 | 久久手机免费观看| 国产精品毛片va一区二区三区| 亚洲精品免费一二三区| 久久躁日日躁aaaaxxxx| 亚洲欧美韩国| 国内久久精品| 国产精品美女视频网站| 亚洲乱亚洲高清| 久久在线视频在线| 亚洲欧美乱综合| 国产精品视频网址| 亚洲免费在线看| 亚洲一区二区在线播放| 欧美日韩一区自拍| 亚洲午夜精品| 亚洲欧美国产va在线影院| 国产精品剧情在线亚洲| 午夜精品视频在线观看| 亚洲一区二区三区色| 国产精品日韩高清| 欧美伊久线香蕉线新在线| 午夜国产精品影院在线观看| 国产精品影音先锋| 久久久国产精品一区二区中文| 欧美一区二区三区视频免费| 狠狠入ady亚洲精品| 欧美a级片网站| 欧美大片免费久久精品三p| 一本久久综合亚洲鲁鲁| 正在播放欧美视频| 国产一区二区成人| 欧美激情国产日韩| 欧美日韩国产成人在线免费| 亚洲综合欧美日韩| 午夜精品区一区二区三| 在线观看免费视频综合| 欧美电影电视剧在线观看| 免费中文日韩| 亚洲女同性videos| 久久国产福利国产秒拍| 亚洲精品偷拍| 亚洲制服丝袜在线| 亚洲高清精品中出| 亚洲人在线视频| 国产欧美视频一区二区三区| 男女激情视频一区| 欧美日韩在线三区| 久久偷看各类wc女厕嘘嘘偷窃| 久久亚洲春色中文字幕久久久| 日韩视频亚洲视频| 欧美在线视频日韩| 亚洲无限乱码一二三四麻| 久久国产精品一区二区三区| 亚洲狼人综合| 欧美中文在线视频| 亚洲午夜一区二区三区| 久久综合色一综合色88| 亚洲欧美日韩在线播放| 蜜月aⅴ免费一区二区三区| 亚洲一区二区三区精品在线| 久久久综合激的五月天| 亚洲综合精品| 欧美极品在线观看| 久久久免费av| 国产精品乱码一区二区三区| 欧美福利视频网站| 国产偷国产偷亚洲高清97cao| 91久久国产自产拍夜夜嗨| 免费成人黄色av| 一区二区精品国产| 亚洲福利小视频| 亚洲女ⅴideoshd黑人| 亚洲高清不卡在线| 久久国产精品亚洲va麻豆| 亚洲一区激情| 欧美精品www| 欧美激情欧美狂野欧美精品| 国产嫩草影院久久久久| 亚洲久色影视| 99热这里只有成人精品国产| 久久久久国产一区二区三区四区| 午夜精品偷拍| 国产精品久久久久久久久久直播 | 午夜性色一区二区三区免费视频 | 免费欧美电影| 久久综合久久美利坚合众国| 久久精品国产v日韩v亚洲 | 亚洲午夜电影网| 亚洲视频综合在线| 欧美日韩国产不卡| 99国产精品视频免费观看| 亚洲精品日产精品乱码不卡| 免费国产一区二区| 亚洲国产裸拍裸体视频在线观看乱了| 精品电影在线观看| 老司机精品视频网站| 美女视频黄 久久| 亚洲二区免费| 免费欧美电影| 亚洲人成7777| 亚洲天堂免费观看| 国产精品毛片在线| 香港久久久电影| 蜜桃av噜噜一区| 亚洲乱码国产乱码精品精98午夜| 欧美不卡视频一区| 91久久线看在观草草青青| aa成人免费视频| 国产精品国产三级国产专播精品人| 在线亚洲伦理| 老司机精品导航| 亚洲精品国精品久久99热| 欧美三级视频| 午夜在线观看免费一区| 麻豆精品精华液| 一区二区三区日韩精品视频| 国产精品美女午夜av| 久久久久久久999| 亚洲免费电影在线观看| 欧美一级久久久久久久大片| 国内精品国产成人| 欧美高清不卡| 午夜在线一区| 亚洲激情自拍| 久久免费一区| 亚洲私人影院在线观看| 黄色亚洲精品| 国产精品久久77777| 久久久久久久91| 在线视频日本亚洲性| 一本到12不卡视频在线dvd| 国产精品免费小视频| 亚洲欧美视频一区二区三区| 美女视频网站黄色亚洲| 亚洲美女一区| 国产一区二区成人久久免费影院| 蜜桃伊人久久| 欧美亚洲免费| 亚洲精品网址在线观看| 久久久亚洲影院你懂的| 99精品国产99久久久久久福利| 国产精品爽爽爽| 欧美美女福利视频| 久久久久久亚洲精品杨幂换脸| 日韩视频二区| 欧美激情一区二区三区在线视频观看 | 免费观看亚洲视频大全| 亚洲天堂av综合网| 在线观看欧美激情| 国产网站欧美日韩免费精品在线观看| 欧美精品一区二区三区四区 | 国产精品日韩久久久| 欧美激情亚洲精品| 久久久综合网站| 久久精品国产免费观看|