题解:P16687 复习
这道题很明显的贪心啊,为什么题解都用的 dp。
思路:首先肯定先学习第三科,然后把第二课用完。
然后要分情况讨论:
记得特判特殊情况。
代码:
#include<bits/stdc++.h>
using namespace std;
int x,y,z,ans;
int main(){
cin>>x>>y>>z;
if(z!=0){
z--;
ans++;
ans+=2*y;
y=0;
if(z>=x){
ans+=2*(z-x+1);
ans+=2;
ans+=3*(x-1);
}
else{
ans+=3*z;
ans+=2;
if(x-z>=2) ans++;
}
cout<<ans;
}
else if(x!=0) cout<<y+1;
else cout<<y;
}
2026/6/6 :把代码改了,感谢 hack。