题目:
6种球, 价值分别为1..6, 给出每种的数量, 问能不能分成价值相同的两堆
思路:
1. 将它当成背包问题来看, 包的容积一定(这里的”体积”就是球的价值, 包的容积V=球总价值的一半), 问能不能分成相等两堆即, 包是不是能装满.
2. 这里不用球背包问题中的极值, 不存在价值的概念, 所以v数组用bool型就可以.
3. 因为每种球数量有限制所以不是典型的完全背包问题(目前就看了两个..01背包和完全背包), 我对v中的每一个true它后面每i个赋值成为true, 直到这层的球耗尽. 比如开始v[0]=true v[1..V]=false, 1球的数量为10, 则第一层i循环后, v[0..10]=true v[11.V]=false
4. 3中直接赋值会对后面的计算有影响, 我很蹩脚的另外建了个列表作临时用…
5. 一次AC, 但是时间效率很低, 7XXms..都快超了(大家都爱说..都快超了), 感觉应该是算法过于繁琐..还倒来倒去的, 有空得试试O(log V/c[i])那算法
6. <背包九讲>下载 http://axlarts.com/uploads/documents/pack9lessons.doc 没作者 没写版权声明 直接转了..
代码:
[cpp] #include <cstdio>
#include <cstring>
int main() {
int n[7],N,V;
bool v[60001],t[60001];
N=0;
while(++N) {
V=0;
bool isEnd=true;
for(int i=1;i<=6;i++) {
scanf("%d",n+i);
V+=n[i]*i;
if(n[i])
isEnd=false;
}
if(isEnd)
break;
printf("Collection #%d:\n",N);
if(V%2) {
printf("Can’t be divided.\n\n");
continue;
}
///initialize
V/=2;
v[0]=true;
memset(v+1,false,V);
for(int i=1;i<=6;i++) {
memset(t,false,V+1);
for(int j=0;j<=V;j++) {
if(!v[j])
continue;
for(int k=0;k<=n[i]*i;k+=i) {
if((j+k)>V)
break;
t[j+k]=true;
}
}
for(int j=1;j<=V;j++)
v[j]=t[j];
}
if(v[V])
printf("Can be divided.\n\n");
else
printf("Can’t be divided.\n\n");
}
return 0;
}[/cpp]
准备留在灵异事件下面..因为今天带电脑也出了这个问题..一听耳熟,是以前练街舞的曲子..不知道什么程序再放..然后听写歌词把它goo出来了..HO..(我去刷新..)
没说完…留在这下面是因为这里留的人少..平均分配资源..感觉你所有的日志都有人留言..牛鞭..
嗯 人人都爱杀花..
不过没人愿意在这陀crap上留言..
呵呵,看过几个你写的代码了,大家一起努力把!
ACM就是有意思啊。
啦啦啦 =D
每篇都有留言是某人偶尔鞭策一下……
#include
#include
int shuzu[7];
int f(int n,int sum)
{
int s=0,i=0,t=0;
if(!sum)
return 1;
if(!n)
if(sum)
return 0;
for(i=0;isum)
break;
if(s>sum)
s-=n;
for(i=s/n;i>=0;i–)
for(t=1;t=sum-i*n)
if(f(n-1,sum-i*n))
return 1;
return 0;
}
void main(void)
{
int num=0,h=0,n=0;
while(1)
{ n=0;
memset(shuzu,0,sizeof(int)*7);
for(h=1;h<=6;n+=shuzu[h]*h,h++)
scanf("%d",shuzu+h);
if(!n)
break;
if(n%2)
printf("Collection #%d:\nCan't be divided.\n\n",++num);
else if(f(6,n/2))
printf("Collection #%d:\nCan be divided.\n\n",++num);
else
printf("Collection #%d:\nCan't be divided.\n\n",++num);
}
}
References:
Legiano Casino Betrug free-psd-templates.com
References:
Kingmaker Casino Bewertungen https://csvip.me/coyjudge996303
References:
KingMaker kreditkarte einzahlung link.epicalorie.shop
References:
Kingmaker Casino VIP https://qr.dsd.edu.gh/georgiablancha
References:
Kingmaker Casino Lizenz https://mssq.me/
References:
KingMaker einzahlung ohne gebühren 31.cholteth.com
References:
KingMaker einzahlung anleitung https://cmbe-console.worldoftanks.com/frame/?service=frm&;project=wotx&;realm=wgcb&;language=en&;login_url=https://de.trustpilot.com/review/beyondjewellery.de
References:
Kingmaker casino mastercard einzahlen ensembl.org
References:
KingMaker Casino Konto einzahlen https://live.warthunder.com/
References:
KingMaker Casino 100% Bonus google.am
References:
KingMaker Casino Einzahlung per Überweisung http://www.google.com.ly/url?sa=t&source=web&cd=1&sqi=2&ved=0CBwQFjAA&url=https://de.trustpilot.com/review/beyondjewellery.de
References:
Legiano Casino Willkommensbonus http://clients1.google.com.na
References:
Legiano Casino Bonus ohne Einzahlung http://clients1.google.sr/
References:
Legiano Casino Verifizierung https://cm-eu.wargaming.net/
References:
KingMaker Casino Einzahlung per Paysafecard http://www.dsl.sk/article_forum.php?action=reply&forum=255549&entry_id=147673&url=https://flowlink.me/pynkj
References:
Legiano Casino Freispiele http://maps.google.com.pa
References:
KingMaker mobile casino echtgeld vaneck.sgn.cornell.edu
References:
KingMaker geld einzahlen http://images.google.com.py/
References:
Kingmaker Casino PayPal https://trac.dpi.inpe.br/terrama2/search?q=https://301.tv/clarkdebavay95
References:
Legiano Casino No Deposit Bonus http://clients1.google.tl/
References:
Kingmaker casino bonus code einzahlung http://wikimapia.org
References:
Kingmaker Casino App ntis.gov
References:
Legiano Casino https://auth.globus.org/v2/web/logout?redirect_uri=https://rentry.co/cgrrmwz4
References:
KingMaker Casino App Download Bonus http://www.google.com.sv/url?sa=t&url=https://sysurl.online/hamishtownsendhttp://www.google.com.sv/url?sa=t&url=https://sysurl.online/hamishtownsend</a
References:
KingMaker Casino Einzahlung per Lastschrift dsl.sk
References:
Legiano Casino Willkommensbonus http://clients1.google.co.ck/url?q=http://telegra.ph/Legiano-Casino-Casino-Legiano-Offizielle-Seite-Deutschland-06-07-3
References:
Legiano Casino Tischspiele http://oluchi.yn.lt/load_file/index?url=wptavern.com/author/toedetail47/
References:
Legiano Casino Test medical-dictionary.thefreedictionary.com
References:
Legiano Casino iPhone http://maps.google.rs/url?q=https://dudoser.com/user/bamboosky57/
References:
Legiano Casino Spielen cse.google.bs
References:
Hitnspin casino app http://www.niann.ru
References:
Hitnspin casino ohne anmeldung vaneck.sgn.cornell.edu
References:
Monro Casino Kundenservice https://cmbe-console.worldoftanks.com/frame/?service=frm&;project=wotx&;realm=wgcb&;language=en&;login_url=https://computic.com.co/idxtonia68
References:
Hit n spin no deposit bonus http://www.forum.roerich.info
References:
Monro Casino Cashback wartank.ru
References:
Hit n spin promo code http://images.google.fm/url?q=https://illustrators.ru/away?link=https://de.trustpilot.com/review/der-wikinger-shop.de
References:
Hit’n’spin casino 25 euro bonus ohne einzahlung http://images.google.dj/
References:
Hitnspin bonus http://images.google.gy/url?sa=t&url=https://www.russianrealty.ru/bitrix/redirect.php?goto=https://de.trustpilot.com/review/der-wikinger-shop.de
References:
Hitnspin casino paysafecard http://nashi-progulki.ru/bitrix/rk.php?goto=http://sc.news.gov.hk/TuniS/de.trustpilot.com/review/der-wikinger-shop.de
References:
Hit n spin casino app http://dat.2chan.net/
References:
Hit n spin casino no deposit bonus images.google.co.vi
References:
Hitnspin casino ähnliche casinos fenix.astroempires.com
References:
Hit n spin bewertung https://termoportal.ru/proxy.php?link=https://www.orkhonschool.edu.mn/profile/griffinsojconnolly26963/profile