/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 3ms 256.0 KiB
#2 Accepted 3ms 256.0 KiB
#3 Accepted 3ms 256.0 KiB
#4 Accepted 3ms 256.0 KiB
#5 Accepted 2ms 356.0 KiB
#6 Accepted 3ms 372.0 KiB
#7 Accepted 3ms 256.0 KiB
#8 Accepted 3ms 256.0 KiB
#9 Accepted 1ms 336.0 KiB
#10 Accepted 1ms 328.0 KiB

代码

#include<bits/stdc++.h>
using namespace std;
inline const void read(int &a)
{
a=0;
char c=getchar();
while(c<'0'||c>'9')c=getchar();
while(c>='0'&&c<='9')
{
a=a*10+c-'0';
c=getchar();
}
}
int ans=INT_MAX;
struct NOW
{
int n,m;
bool operator==(const NOW a)
{
if(a.n==n&&a.m==m)return true;
else return false;
}
}now[50000];
int n,m,t,d,k=0;
bool solve=false;
int s=0,e=0;
void dp(int step)
{
if(step>t)return ;
for(int o=s;o<=e;o++)
{
int nown=now[o].n,nowm=now[o].m;
ans=min(abs(nown+nowm-d),ans);
if(!ans)solve=true;
if(solve)return ;
bool yes=true;
if(nown<n)
{
now[k+1].n=n;
now[k+1].m=nowm;
for(int i=0;i<=k;i++)
if(now[k+1]==now[i]){yes=false;break;}
if(yes)k++;
}
yes=true;
if(nowm<m)
{
now[k+1].m=m;
now[k+1].n=nown;
for(int i=0;i<=k;i++)
if(now[k+1]==now[i]){yes=false;break;}
if(yes)k++;
}
yes=true;
if(nown)
{
now[k+1].n=0;
now[k+1].m=nowm;
for(int i=0;i<=k;i++)
if(now[k+1]==now[i]){yes=false;break;}
if(yes)k++;
}
yes=true;
if(nowm)
{
now[k+1].m=0;
now[k+1].n=nown;
for(int i=0;i<=k;i++)
if(now[k+1]==now[i]){yes=false;break;}
if(yes)k++;
}
yes=true; 
if(nown>0&&nowm<m)
{
if(nown+nowm<=m)
{
now[k+1].n=0;
now[k+1].m=nown+nowm;
}
else
{
now[k+1].n=nown+nowm-m;
now[k+1].m=m;
}
for(int i=0;i<=k;i++)
if(now[k+1]==now[i]){yes=false;break;}
if(yes)k++;
}
yes=true;
if(nowm>0&&nown<n)
{
if(nown+nowm<=n)
{
now[k+1].n=nown+nowm;
now[k+1].m=0;
}
else
{
now[k+1].n=n;
now[k+1].m=nown+nowm-n;
}
for(int i=0;i<=k;i++)
if(now[k+1]==now[i]){yes=false;break;}
if(yes)k++;
}
yes=true;
}
s=e+1;
e=k;
dp(step+1);
}
int main()
{
read(n);read(m);read(t);read(d);
now[0].n=now[0].m=0;
dp(0);
printf("%d",ans);
return 0;
}

信息

递交者
类型
递交
题目
杯具
题目数据
下载
语言
C++
递交时间
2017-08-06 20:03:34
评测时间
2017-08-06 20:03:34
评测机
分数
100
总耗时
27ms
峰值内存
372.0 KiB