4004: [JLOI2015]装备购买
Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 1752 Solved: 526
[ Submit][ Status][ Discuss]
Description
脸哥最近在玩一款神奇的游戏,这个游戏里有 n 件装备,每件装备有 m 个属性,用向量zi(aj ,.....,am) 表示
(1 <= i <= n; 1 <= j <= m),每个装备需要花费 ci,现在脸哥想买一些装备,但是脸哥很穷,所以总是盘算着
怎样才能花尽量少的钱买尽量多的装备。对于脸哥来说,如果一件装备的属性能用购买的其他装备组合出(也就是
说脸哥可以利用手上的这些装备组合出这件装备的效果),那么这件装备就没有买的必要了。严格的定义是,如果
脸哥买了 zi1,.....zip这 p 件装备,那么对于任意待决定的 zh,不存在 b1,....,bp 使得 b1zi1 + ... + bpzi
p = zh(b 是实数),那么脸哥就会买 zh,否则 zh 对脸哥就是无用的了,自然不必购买。举个例子,z1 =(1; 2;
3);z2 =(3; 4; 5);zh =(2; 3; 4),b1 =1/2,b2 =1/2,就有 b1z1 + b2z2 = zh,那么如果脸哥买了 z1 和 z2
就不会再买 zh 了。脸哥想要在买下最多数量的装备的情况下花最少的钱,你能帮他算一下吗?
Input
第一行两个数 n;m。接下来 n 行,每行 m 个数,其中第 i 行描述装备 i 的各项属性值。接下来一行 n 个数,
其中 ci 表示购买第 i 件装备的花费。
Output
一行两个数,第一个数表示能够购买的最多装备数量,第二个数表示在购买最多数量的装备的情况下的最小花费
Sample Input
3 3
1 2 3
3 4 5
2 3 4
1 1 2
1 2 3
3 4 5
2 3 4
1 1 2
Sample Output
2 2
HINT
如题目中描述,选择装备 1 装备 2,装备 1 装备 3,装备 2 装备 3 均可,但选择装备 1 和装备 2 的花费最小,为 2。对于 100% 的数据, 1 <= n;m <= 500; 0 <= aj <= 1000。
新加数据三组--2016.5.13
Source
#include<cstdio> #include<vector> #include<queue> #include<ctime> #include<algorithm> #include<cstdlib> #include<stack> #include<cstring> #include<cmath> using namespace std; typedef long long LL; typedef long double DL; const int INF = 2147483647; const int maxn = 510; const DL eps = 1e-7; struct data{ DL m[maxn]; LL c; }; LL ans; int n,m; data a[maxn]; inline LL getint() { LL ret = 0,f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') ret = ret * 10 + c - '0',c = getchar(); return ret * f; } inline bool cmp(data a,data b) { return a.c < b.c; } inline int gauss() { int to,now = 1; DL t; for (int i = 1; i <= m; i++) { for (to = now; to <= n; to++) if (fabs(a[to].m[i]) > eps) break; if (to > n) continue; if (to != now) swap(a[to],a[now]); ans += a[now].c; t = a[now].m[i]; for (int j = 1; j <= m; j++) if (a[now].m[j]) a[now].m[j] /= t; for (int j = 1; j <= n; j++) { if (j == now) continue; t = a[j].m[i]; for (int k = 1; k <= m; k++) a[j].m[k] -= a[now].m[k] * t; } now++; } return now - 1; } int main() { #ifdef AMC freopen("AMC1.txt","r",stdin); #endif n = getint(); m = getint(); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) a[i].m[j] = getint(); for (int i = 1; i <= n; i++) a[i].c = getint(); sort(a + 1,a + n + 1,cmp); int ret = gauss(); printf("%d %lld\n",ret,ans); return 0; }