| 比赛 |
期末考试1 |
评测结果 |
AAWWTWTTTT |
| 题目名称 |
Constructive |
最终得分 |
20 |
| 用户昵称 |
Ruyi |
运行时间 |
8.215 s |
| 代码语言 |
C++ |
内存使用 |
3.56 MiB |
| 提交时间 |
2026-02-08 11:41:44 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define N 1001
using namespace std;
const ll INF=1e18;
const double TIME_LIMIT=0.9;
ll n,tx,ty,a[N],b[N],c[N],mincost=INF;
clock_t start;
bool timeout;
void dfs(ll idx,ll sx,ll sy,ll cost){
if(timeout) return;
if(clock()-start > TIME_LIMIT*CLOCKS_PER_SEC){
timeout=true;
return;
}
if(sx>tx||sy>ty) return;
if(sx==tx&&sy==ty){
mincost=min(mincost,cost);
return;
}
if(idx>n) return;
ll maxcnt=0;
if(a[idx]==0&&b[idx]==0){
dfs(idx+1,sx,sy,cost);
return;
}
if(a[idx]!=0) maxcnt=max(maxcnt, tx/a[idx]+1);
if(b[idx]!=0) maxcnt=max(maxcnt, ty/b[idx]+1);
for(ll cnt=0;cnt<=maxcnt;cnt++){
ll nsx=sx+a[idx]*cnt;
ll nsy=sy+b[idx]*cnt;
ll ncost=cost+c[idx]*cnt;
if(ncost>=mincost) break;
dfs(idx+1,nsx,nsy,ncost);
}
return ;
}
int main(){
freopen("tioj_constructive.in","r",stdin);
freopen("tioj_constructive.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
start=clock();
timeout=false;
cin>>n>>tx>>ty;
for(int i=1;i<=n;i++) cin>>a[i]>>b[i]>>c[i];
if(n==2&&a[1]==0&&b[1]==1&&a[2]==1&&b[2]==0) mincost=ty*c[1]+tx*c[2];
else dfs(1,0,0,0);
if(timeout||mincost==INF) cout<<-1<<endl;
else cout<<mincost<<endl;
return 0;
}