BZOJ 4393: [Usaco2015 Dec]Fruit Feast
DP
#include<cstdio> using namespace std; int T,A,B,F[5000005],G[5000005]; int main(){ scanf("%d%d%d",&T,&A,&B); F[0]=1; for (int i=0; i<=T; i++) F[i+A]|=F[i],F[i+B]|=F[i]; for (int i=0; i<=T; i++) G[i/2]|=F[i]; for (int i=0; i<=T; i++) G[i+A]|=G[i],G[i+B]|=G[i]; for (int i=T; i>=0; i--) if (F[i] || G[i]){ printf("%d\n",i); return 0; } return 0; }