Created
February 16, 2017 14:47
-
-
Save takageymt/546d2baea266df46596f6fc735e67cfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define int long long | |
#define all(v) begin(v), end(v) | |
#define rep(i, n) for(int i = 0; i < (int)(n); i++) | |
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++) | |
#define min(...) min({__VA_ARGS__}) | |
#define max(...) max({__VA_ARGS__}) | |
const int inf = 1LL << 55; | |
const int mod = 1e9 + 7; | |
signed main() | |
{ | |
cin.tie(0); | |
ios_base::sync_with_stdio(0); | |
cout << fixed << setprecision(12); | |
int N, Ma, Mb; | |
cin >> N >> Ma >> Mb; | |
int a[N], b[N], c[N]; | |
rep(i, N) cin >> a[i] >> b[i] >> c[i]; | |
int dp[401][401]; | |
fill(dp[0], dp[401], inf); | |
dp[0][0] = 0; | |
rep(i, N) { | |
for(int j = 400; j >= a[i]; j--) { | |
for(int k = 400; k >= b[i]; k--) { | |
dp[j][k] = min(dp[j][k], dp[j-a[i]][k-b[i]] + c[i]); | |
} | |
} | |
} | |
int ans = inf; | |
reps(i, 1, 401) reps(j, 1, 401) { | |
if(i*Mb == j*Ma) ans = min(ans, dp[i][j]); | |
} | |
cout << (ans == inf ? -1 : ans) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment