标签:lse www. int char ++i set min read eof
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define N 1005
#define inf 0x3f3f3f3f
using namespace std;
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
inline int Min(register int a,register int b)
{
return a<b?a:b;
}
int n,T[N],B[N],f[N][1<<8][20];
int main()
{
int t=read();
while(t--)
{
n=read();
for(register int i=1;i<=n;++i)
T[i]=read(),B[i]=read();
memset(f,inf,sizeof(f));
f[1][0][7]=0;
for(register int i=1;i<=n;++i)
for(register int j=0;j<(1<<8);++j)
for(register int k=-8;k<=7;++k)
if(f[i][j][k+8]!=inf)
{
if(j&1)
f[i+1][j>>1][k+7]=Min(f[i+1][j>>1][k+7],f[i][j][k+8]);
else
{
int x=inf;
for(register int h=0;h<=7;++h)
if(!((j>>h)&1))
{
if(i+h>x)
break;
x=Min(x,i+h+B[i+h]);
f[i][j|(1<<h)][h+8]=Min(f[i][j|(1<<h)][h+8],f[i][j][k+8]+(i+k?(T[i+k]^T[i+h]):0));
}
}
}
int ans=inf;
for(register int k=0;k<=8;++k)
ans=Min(ans,f[n+1][0][k]);
printf("%d\n",ans);
}
return 0;
}
【题解】Luogu P2157 [SDOI2009]学校食堂
标签:lse www. int char ++i set min read eof
原文地址:https://www.cnblogs.com/yzhang-rp-inf/p/9743517.html