从左到右DP, 存储哪里有奶牛以后排序, 同一个x坐标的上下奶牛合并.. 0没有 1上 2下 3都有
随着奶牛的位置x从左到右DP, 需要记录的状态是dp[i][p][k], p是在x处的奶牛圈起来的方式, 我记的是 0没圈(这就初始状态可能) 1圈上 2圈下 3两个一起圈 4两个分开圈, 记录每个可能的k和对应的面积最小值
状态转移比较麻烦.. 我是又分两个状态之间的圈圈怎样互相结合来枚举, 0不结合 1上边延伸出去 2下边 3两边一起延伸 4两边分开延伸. 应该还有更巧妙的方法.. 不想再碰这题了
172ms 直接大数组20M内存..代码点下面
[cpp]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int adoptable(int p,int q) {
if(p==3||p==4)
return q==p?0:-1;
if(p==1||p==2) {
if(q==p)
return 0;
if(q==4)
return 1;
return -1;
}
//p==0;
return q==0?0:q==4?2:1;
}
int ifAddK(int p0,int p1,int stretch) {
if(adoptable(stretch,p0)==-1)
return -1;
return adoptable(stretch,p1);
}
int cmp(const void *_a, const void *_b) {
int a=*(int *)_a,b=*(int *)_b;
return (a>>3)-(b>>3);
}
int main() {
int N,K,B;
scanf("%d%d%d",&N,&K,&B);
int map[1001];
for(int i=1;i<=N;i++)
map[i]=-1;
int mapN=0;
for(int i=1;i<=N;i++) {
int u,pos;
scanf("%d%d",&u,&pos);
int j;
for(j=1;j<=mapN;j++)
if( (map[j]>>3)==pos )
break;
if(j>mapN) {
map[j]= (pos<<3)|u;
mapN++;
}
else
map[j]|=u;
}
qsort(map+1,mapN,sizeof(int),cmp);
int (*dp)[5][1001];
dp=(int (*)[5][1001])malloc(sizeof(int)*1001*5*1001);
memset(dp[0],0xff,sizeof(dp[0]));
dp[0][0][0]=0;
map[0]=0;
for(int i=1;i<=mapN;i++) {
memset(dp[i],0xff,sizeof(dp[0]));
for(int p0=0;p0<=4;p0++) //Statu of last
for(int p1=0;p1<=4;p1++) // This state
{
if(p1!=4 && (p1|(map[i]&3))!=p1)
continue;
for(int stretch=0;stretch<=4;stretch++) //which side stretching
{
int addK=ifAddK(p0,p1,stretch);
if(addK==-1)
continue;
int addC=(map[i]>>3)-(map[i-1]>>3)-1;
addC*=(stretch==1||stretch==2)?1:stretch==0?0:2;
addC+=(p1==0)?0:(p1==1||p1==2)?1:2;
for(int k=0;k<=K;k++) {
int k1=k+addK;
if(k1>K)
break;
if(dp[i-1][p0][k]==-1)
continue;
if(dp[i][p1][k1]==-1||dp[i][p1][k1]>dp[i-1][p0][k]+addC)
dp[i][p1][k1]=dp[i-1][p0][k]+addC;
}
}
}
}
int result=2e9;
for(int p=0;p<=4;p++)
result=dp[mapN][p][K]!=-1&&dp[mapN][p][K]<result?dp[mapN][p][K]:result;
printf("%d\n",result);
return 0;
}
[/cpp]
References:
Hitnspin verifizierung https://12.rospotrebnadzor.ru/
References:
Hit n spin casino 25 euro code https://wiki.opendesign.com
References:
Hitnspin casino aktionscode http://hotubi.com/go.php?url=https://briefjournal.space/item/casino-bonus-ohne-einzahlung-140-aktuelle-angebote-in-juni-2026
References:
Hit spin casino https://fmodpro.com/
References:
Hitnspin casino auszahlungslimit https://xgm.guru/go/https://atavi.com/share/xvvexqz1pfhmd/
References:
Hitnspin casino auszahlung https://board-en.farmerama.com
References:
Lollybet Casino 10 Euro Bonus toolbarqueries.google.com.eg
References:
Lollybet Casino Auszahlungsdauer clients1.google.com.sa
References:
Lollybet Casino Mindesteinzahlung http://kimberly-club.ru
References:
Lollybet Casino No Deposit Bonus clients1.google.ee
References:
Lollybet Casino Mindesteinzahlung google.co.nz
References:
Lollybet Einzahlung rufox.com
References:
Lollybet Casino Verifizierung http://cse.google.no/url?q=http://diendan.gamethuvn.net/proxy.php?link=https://lollybet.com.de/
References:
Hit n spin casino no deposit bonus http://clients1.google.com.sa/
References:
Hit n spin casino bonus code clients1.google.com.cy
References:
Hit n spin clients1.google.com.fj
References:
Hitnspin casino auszahlung erfahrungen aintedles.yoo7.com
References:
Hit and spin casino alt1.toolbarqueries.google.com.nf
References:
Hit n spin casino bonus http://cse.google.cl/url?q=http://kriminal-ohlyad.com.ua/user/lightnylon5/
References:
Hitnspin casino live spiele http://cse.google.ad/url?sa=t&url=https://www.24propertyinspain.com/user/profile/1453485
References:
Hit’n spin casino http://ezproxy.lib.uh.edu/
References:
Hitnspin promo code http://images.google.co.vi
References:
Hitnspin erfahrungen lginis.yoo7.com
References:
Hitnspin casino auszahlung clients1.google.lv
References:
Hitnspin casino betrug http://alt1.toolbarqueries.google.ac
References:
Hit n spin casino erfahrungen http://cse.google.iq
References:
Online pokies with payid streemie.com
References:
Payid pokies aus https://trust-employement.com
References:
Payid online pokies australia https://code.dsconce.space/
References:
Online pokies with payid australia real money worldclassdjs.com
References:
Australian online pokies payid https://bbclinic-kr.com/
References:
Australia online pokies payid https://jobs.capsalliance.eu/employer/explore-the-best-payid-casinos-australia-in-2026-where-to-find-fast-cashouts-and/
References:
Online pokies real money payid https://www.itubee.com/@robertohanton4?page=about
References:
Payid pokies online https://www.bud108.com/bbs/board.php?bo_table=free&wr_id=133356
References:
Lollybet Casino Mindesteinzahlung http://clients1.google.se/url?sa=t&url=https://gmaweb.online/terrifairley5
References:
Lollybet Aktionscode https://ore.spongepowered.org/linkout?remoteUrl=https://linknest.vip/marcellaa03178
References:
Lollybet Casino Roulette https://acronyms.thefreedictionary.com/_/cite.aspx?url=https://allbio.link/callummari&word=Associacio%20Catalana%20d%27Educacio%20Medica&sources=acr
References:
Lollybet Casino http://tiwar.ru/?channelId=298&partnerUrl=https://www.mydaradstools.com/bernardf38/
References:
Lollybet Casino Bonus ohne Umsatzbedingungen https://fr.chaturbate.com/external_link/?url=https://link.epicalorie.shop/marylynlyall88
References:
Lollybet Casino Kundenservice http://images.google.lv/url?q=https://gabung.link/dkgaiden581094
References:
Lollybet Online Casino http://sekkotsu-e.sakura.ne.jp/mt_mobile/mt4i.cgi?id=2&mode=redirect&no=35&ref_eid=3&url=https://getshort.in/addie68a479772
References:
Lollybet Casino Gutscheincode http://image.google.com.om/url?q=https://t2m.kr/pzmashly515097
References:
Lollybet Casino Live Casino http://www.google.com.qa/url?q=https://url79.com/diegowakefield
References:
Lollybet Kontakt http://test-app.school2100.com/bitrix/rk.php?goto=https://searl.co/jerriphipps851
References:
Rivers casino pittsburgh https://academy.tatiosa.com/forums/users/antoinettepettey/
References:
Casinos of winnipeg https://pracaeuropa.pl/companies/instant-casino-bonus-2026-alle-angebote-regeln-fur-deutsche-spieler/
References:
Old second neteller https://punbb.skynettechnologies.us/viewtopic.php?id=500978
References:
Apex casino https://career.braincode.com.bd/employer/instant-casino-at-live-casino-und-bonus-aktionen-online/
References:
Lollybet Casino Spielautomaten http://www.gewindesichern.de/?URL=https://www.cbl.aero/employer/lollybet-casino-erfahrungen-2026-sicher-oder-ein-betrug/
References:
Lollybet Casino 10 Euro Bonus http://www.google.pl/url?q=https://talentlagoon.com/employer/lollybet-casino-bonus-30-freispiele-ohne-einzahlung-bonus-ohne-einzahlung-2026/