牛客小白月赛69 C题-开题顺序 DFS
开题顺序
https://ac.nowcoder.com/acm/contest/54437/C
u表示写第几题,ti表示用了多少时间,B数组表示该题是否在当前方案内写过
剪枝注意判断当前方案剩余时间是否够用
using namespace std;
const int N=12;
long long int n,t,p,ti,imax,sum=0;
struct aa{
long long int a,b,c,x,y;
}A[N];
int B[N];
void dfs(int u,int ti) {
if (u<=n) {
for (int i=1;i<=n;i++) {
if (B[i]==0&&ti+A[i].x<=t) {
ti+=A[i].x;
long long int s=max(A[i].c,A[i].a-ti*A[i].b-A[i].y*p);
sum+=s;
B[i]=1;
dfs(u+1,ti);
if (sum>imax) imax=sum;
sum-=s;
ti-=A[i].x;
B[i]=0;
}
}
}
}
int main()
{
scanf("%lld %lld %lld",&n,&t,&p);
for (int i=1;i<=n;i++) {
scanf("%lld %lld %lld %lld %lld",&A[i].a,&A[i].b,&A[i].c,&A[i].x,&A[i].y);
}
dfs(1,0);
cout << imax;
return 0;
}