为什么第95个测试点不能过?

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>

using namespace std;
const int MAX=700;
int i,j,k,n,m,a[MAX],c[MAX],x,y,ans,T;

int get_ans()
{
int tot=0;
memset(c,0,sizeof(c));
for (i=0;i<=13;i++) c[a[i]]++;
while ((c[4])&&(c[2]>1))
{
c[4]--;
c[2]-=2;
tot++;
}
while ((c[4])&&(c[1]>1))
{
c[4]--;
c[1]-=2;
tot++;
}
while ((c[4])&&(c[2]))
{
c[4]--;
c[2]--;
tot++;
}
while ((c[3])&&(c[2]))
{
c[3]--;
c[2]--;
tot++;
}
while ((c[3])&&(c[1]))
{
c[3]--;
c[1]--;
tot++;
}
return tot+c[1]+c[2]+c[3]+c[4];
}

void dfs(int now)
{
int k1,k2,i,j;
if (now>=ans) return;
int res=get_ans();
if (res+now<ans) ans=res+now;
for (i=2;i<=13;i++)
{
j=i;
while (a[j]>=3) j++;
if (j-i>=2)
{
for (k1=i+1;k1<=j-1;k1++)
{
for (k2=i;k2<=k1;k2++) a[k2]-=3;
dfs(now+1);
for (k2=i;k2<=k1;k2++) a[k2]+=3;

}
}

}
for (i=2;i<=13;i++)
{
j=i;
while (a[j]>=2) j++;
if (j-i>=3)
{
for (k1=i+2;k1<=j-1;k1++)
{
for (k2=i;k2<=k1;k2++) a[k2]-=2;
dfs(now+1);
for (k2=i;k2<=k1;k2++) a[k2]+=2;

}
}

}
for (i=2;i<=13;i++)
{
j=i;

while (a[j]>=1) j++;
if (j-i>=5)
{
for (k1=i+4;k1<=j-1;k1++)
{
for (k2=i;k2<=k1;k2++) a[k2]--;
dfs(now+1);
for (k2=i;k2<=k1;k2++) a[k2]++;
}
}

}
}

int main()
{
freopen("landlords.in","r",stdin);
freopen("landlords.out","w",stdout);
cin>>T>>n;
//memset(a,0,sizeof(a));
while (T--)
{
memset(a,0,sizeof(a));
for (i=1;i<=n;i++)
{
cin>>x>>y;
if (x==1) x=13;
else if (x) x--;
a[x]++;

}
ans=1<<25;
dfs(0);
cout<<ans<<endl;
}
fclose(stdin); fclose(stdout);
return 0;
}

0 条评论

目前还没有评论...

信息

ID
1980
难度
8
分类
(无)
标签
递交数
2591
已通过
352
通过率
14%
被复制
13
上传者