|
| 1 | +#include <cmath> |
| 2 | +#include <set> |
| 3 | +#include <list> |
| 4 | +#include <climits> |
| 5 | +#include <queue> |
| 6 | +#include <vector> |
| 7 | +#include <map> |
| 8 | +#include <set> |
| 9 | +#include <cstdlib> |
| 10 | +#include <fstream> |
| 11 | +#include <iomanip> |
| 12 | +#include <iostream> |
| 13 | +#include <sstream> // istringstream buffer(myString); |
| 14 | +#include <stack> |
| 15 | +#include <algorithm> |
| 16 | +#include <cstring> |
| 17 | +#include <cassert> |
| 18 | +using namespace std; |
| 19 | +#define bit(x,i) (x&(1<<i)) |
| 20 | +#define lowbit(x) ((x)&((x)^((x)-1))) |
| 21 | +//#define max(a,b) (a<b?b:a) |
| 22 | +//#define abs(x) (x<0?-x:x) |
| 23 | +#define IN(i,l,r) (l<i&&i<r) |
| 24 | +#define LINR(i,l,r) (l<=i&&i<=r) |
| 25 | +#define LIN(i,l,r) (l<=i&&i<r) |
| 26 | +#define INR(i,l,r) (l<i&&i<r) |
| 27 | +#define F(i,L,R) for (int i = L; i < R; i++) |
| 28 | +#define FE(i,L,R) for (int i = L; i <= R; i++) |
| 29 | +#define FF(i,L,R) for (int i = L; i > R; i--) |
| 30 | +#define FFE(i,L,R) for (int i = L; i >= R; i--) |
| 31 | +#define char2Int(c) (c-'0') |
| 32 | +#define lastEle(vec) vec[vec.size()-1] |
| 33 | +#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) |
| 34 | +#define clr(a,x) memset(a,x,sizeof(a)) |
| 35 | +#define getI(a) scanf("%d", &a) |
| 36 | +#define getII(a,b) scanf("%d%d", &a, &b) |
| 37 | +#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c) |
| 38 | +#define getS(x) scanf("%s", x); |
| 39 | +#define SZ(x) ((int)((x).size())) |
| 40 | +#define REMAX(a,b) (a)=max((a),(b)); |
| 41 | +#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl; |
| 42 | +#define REMIN(a,b) (a)=min((a),(b)); |
| 43 | +#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) |
| 44 | +#define ALL(t) t.begin(),t.end() |
| 45 | +#define ll long long |
| 46 | +#define ull unsigned long long |
| 47 | +#define ui unsigned int |
| 48 | +#define us unsigned short |
| 49 | +#define IOS ios_base::sync_with_stdio(0); |
| 50 | +#define pb push_back |
| 51 | +#define INF 1001001001 |
| 52 | +#define PI 3.1415926535897932384626 |
| 53 | +#define mp make_pair |
| 54 | +#define ll long long |
| 55 | +#define fi first |
| 56 | +#define se second |
| 57 | +#define wez(n) int (n); scanf("%d",&(n)); |
| 58 | +#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m)); |
| 59 | +#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k)); |
| 60 | +inline void pisz(int n) { printf("%d\n",n); } |
| 61 | +#define TESTS wez(testow)while(testow--) |
| 62 | +#define whileZ int T; getI(T); while(T--) |
| 63 | +#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ') |
| 64 | +#define printM(a,n,m) F(i,0,n){ F(j,0,m) cout << a[i][j] << ' '; cout << endl;} |
| 65 | +#define printV(a) printA(a,0,a.size()-1); |
| 66 | +#define printVV(a) F(i,0,a.size()) {F(j,0,a[i].size())cout << a[i][j] << ' '; cout << endl;} |
| 67 | +#define MAXN 10000 |
| 68 | +#define sz(a) int((a).size()) |
| 69 | +#define pb push_back |
| 70 | +#define all(c) (c).begin(),(c).end() |
| 71 | +#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++) |
| 72 | +#define present(c,x) ((c).find(x) != (c).end()) |
| 73 | +#define cpresent(c,x) (find(all(c),x) != (c).end()) |
| 74 | +typedef int elem_t; |
| 75 | +typedef vector<int> vi; |
| 76 | +typedef vector<vi> vvi; |
| 77 | +typedef pair<int,int> ii; |
| 78 | +template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";} |
| 79 | +template<typename T> ostream& operator<<(ostream &s,vector<T> t){F(i,0,SZ(t))s<<t[i]<<" ";return s; } |
| 80 | +int gcd(int a,int b){return a?gcd(b%a,a):b;} |
| 81 | +ll gcd(ll a,ll b){return a?gcd(b%a,a):b;} |
| 82 | +ll powmod(ll a,ll p,ll m){ll r=1;while(p){if(p&1)r=r*a%m;p>>=1;a=a*a%m;}return r;} |
| 83 | +const int fx[4][2] = {{0,1}, {1,0}, {0,-1}, {-1,0}}; |
| 84 | +struct node{ |
| 85 | + ll money, monitor, solve; |
| 86 | +}a[100]; |
| 87 | +ll f[2][1 << 20]; |
| 88 | +ll n,k,b; |
| 89 | +ll solve(ll M){ |
| 90 | + clr(f, -1); |
| 91 | + ll KK = 1 << k; |
| 92 | + f[0][0] = f[1][0] = 0; |
| 93 | + for (ll i = 0; i < n; i++) if (a[i].monitor <= M){ |
| 94 | + for (ll s = 0; s < KK; s++) if (f[0][s] != -1){ |
| 95 | + ll t = s | a[i].solve; |
| 96 | + if (f[1][t] == -1 || f[0][s] + a[i].money < f[1][t]) |
| 97 | + f[1][t] = a[i].money + f[0][s]; |
| 98 | + } |
| 99 | + memcpy(f[0], f[1], sizeof(f[0])); |
| 100 | + } |
| 101 | + if (f[0][KK-1] == -1) return LONG_LONG_MAX; |
| 102 | + else return f[0][KK-1] + b * M; |
| 103 | +} |
| 104 | +int main( int argc, char *argv[] ) { |
| 105 | + cin >> n >> k >> b; |
| 106 | + for (ll i = 0; i < n; i++){ |
| 107 | + ll num; |
| 108 | + cin >> a[i].money >> a[i].monitor >> num; |
| 109 | + a[i].solve = 0; |
| 110 | + F(j,0,num){ |
| 111 | + wez(x); |
| 112 | + x--; |
| 113 | + a[i].solve |= 1 << x; |
| 114 | + } |
| 115 | + } |
| 116 | + ll minM = LONG_LONG_MAX; |
| 117 | + set<ll> visited; |
| 118 | + for (ll i = 0; i < n; i++) if (visited.find(a[i].monitor) == visited.end()){ |
| 119 | + visited.insert(a[i].monitor); |
| 120 | + minM = min(minM, solve(a[i].monitor)); |
| 121 | + } |
| 122 | + if (minM == LONG_LONG_MAX) cout << -1 << endl; |
| 123 | + else cout << minM << endl; |
| 124 | + return EXIT_SUCCESS; |
| 125 | +} |
0 commit comments