题目链接:https://begin.lydsy.com/JudgeOnline/problem.php?cid=1258&pid=14
#include <bits/stdc++.h>
using namespace std;
int read()
{
int x=0,f=1;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;
}
int T;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int f[3005][15][40];
bool lea(int x)
{
if(x%400==0||(x%4==0&&x%100!=0))return 1;
return 0;
}
bool jud(int x,int y,int z)
{
if(x>2012||y>12||z>31)return 0;
if(x==2012&&y==12&&z>=23)return 0;
if(y==2)
{
if(z>a[1]+lea(x))return 0;
}
else if(z>a[y-1])return 0;
return 1;
}
int dp(int x,int y,int z)
{
if(x==2012&&y==12&&z==22)return 0;
if(f[x][y][z]!=-1)return f[x][y][z];
int sg[3];memset(sg,0,sizeof(sg));
int tx=x,ty=y,tz=z,lim=a[y-1];
tz++;
if(y==2&&lea(tx))lim++;
if(tz==lim+1)tz=1,ty++;
if(ty==13)tx++,ty=1;
if(jud(tx,ty,tz))sg[dp(tx,ty,tz)]=1;
tx=x,ty=y,tz=z;
ty++;
if(ty==13)tx++,ty=1;
if(jud(tx,ty,tz))sg[dp(tx,ty,tz)]=1;
for(int i=0;i<=3;i++)
if(!sg[i])
return f[x][y][z]=i;
}
int main()
{
memset(f,-1,sizeof(f));
int x,y,z;
while(scanf("%d%d%d",&x,&y,&z)!=EOF)
{
for(int i=2000;i>=1900;i--)dp(i,1,1);
if(dp(x,y,z))puts("YES");
else puts("NO");
}
return 0;
}