4004: [JLOI2015]装备购买

编程入门 行业动态 更新时间:2024-10-26 14:30:33

4004: [JLOI2015]<a href=https://www.elefans.com/category/jswz/34/1768617.html style=装备购买"/>

4004: [JLOI2015]装备购买

4004: [JLOI2015]装备购买

Time Limit: 20 Sec   Memory Limit: 128 MB
Submit: 988   Solved: 337
[ 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

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

[ Submit][ Status][ Discuss]

因为选基的话是拟阵呀。。。所以所有向量按价格升序排好,一个个检查能否当基就行了
可以所有向量放一起,O(n^3)高斯消元。每次选择剩余向量中最便宜的当主元就是了
但是,,,这题。。。。。非常罪恶
这三组数据绝逼是卡精度的。。。原题数据全A的代码交上去还是WA飞。
最后看了网上某神犇,,,用模运算防卡精度,,恍然大悟= =
但是,,常数巨大啊。。跑了6s多。。也没谁了吧
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
#include<ext/pb_ds/priority_queue.hpp>
using namespace std;const int maxn = 505;
typedef long long  LL;
const LL mo = 1000000007;LL Mul(const LL &x,const LL &y) {return x*y%mo;}
LL Dec(const LL &x,const LL &y) {return (x - y + mo) % mo;}struct data{int w,num; data(){}data(int w,int num): w(w),num(num){}bool operator < (const data &b) const {return w < b.w;}
}D[maxn];int n,m,Ans,tot,bs[maxn],A[maxn][maxn],B[maxn][maxn];int ksm(int x,int y)
{int ret = 1;for (; y; y >>= 1){if (y&1) ret = Mul(ret,x);x = Mul(x,x);}return ret;
}int main()
{#ifdef DMCfreopen("DMC.txt","r",stdin);#endifcin >> n >> m;for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)scanf("%d",&B[i][j]);for (int i = 1; i <= n; i++){int w; scanf("%d",&w);D[i] = data(w,i);}sort(D + 1,D + n + 1);for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++)A[i][j] = B[D[i].num][j];for (int i = 1; i <= n; i++)for (int j = 1; j <= m; j++){if (!A[i][j]) continue;if (!bs[j]){bs[j] = i; Ans += D[i].w;++tot; break;}else{int t = Mul(A[i][j],ksm(A[bs[j]][j],mo-2));for (int k = j; k <= m; k++)A[i][k] = Dec(A[i][k],Mul(t,A[bs[j]][k]));}}cout << tot << ' ' << Ans;return 0;
}

更多推荐

4004: [JLOI2015]装备购买

本文发布于:2024-02-11 14:09:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1681390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:装备

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!