hdu 5697 刷题计划
来源:互联网 发布:md5加密java代码百度云 编辑:程序博客网 时间:2024/04/29 13:45
类似最小乘积生成树那样。。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <vector>#include <queue>#include <map>#include <set>#include <algorithm>#include <ctime>#include <functional>#pragma comment(linker,"/STACK:102400000,102400000")using namespace std;#define eps 1e-10#define inf 0x3f3f3f3f#define LL long long#define pii pair<int, int>#define MP make_pair#define md (ll + rr >> 1)#define ls i << 1#define rs ls | 1#define lson ll, md, ls#define rson md + 1, rr, rs#define N 100010#define M 400020struct point{int x, y;point(int x = 0, int y = 0) : x(x), y(y) {}point operator - (const point &b) const {return point(x - b.x, y - b.y);}point operator + (const point &b) const {return point(x + b.x, y + b.y);}};LL cross(point a, point b){return 1LL * a.x * b.y - 1LL * a.y * b.x;}int n, m, sum;int a[N], b[N], c[N];point p[N];LL dp[N], f[N], ans;point gao(){p[0] = point(0, 0), dp[0] = 0;for(int i = 1; i <= sum; ++i) dp[i] = 1LL << 60;for(int i = 1; i <= n; ++i){for(int j = sum; j >= a[i]; --j){if(dp[j] > dp[j-a[i]] + f[i]){dp[j] = dp[j-a[i]] + f[i];p[j] = p[j-a[i]] + point(b[i], c[i]);}}}int ret = m; LL tot = 1LL * p[ret].x * p[ret].y;for(int i = m; i <= sum; ++i) {if(dp[i] < dp[ret] || dp[i] == dp[ret] && 1LL * p[i].x * p[i].y < tot)ret = i, tot = 1LL * p[ret].x * p[ret].y;}ans = min(ans, tot);return p[ret];}void solve(point A, point B){for(int i = 1; i <= n; ++i)f[i] = 1LL * c[i] * (B.x - A.x) + 1LL * b[i] * (A.y - B.y);point C = gao();if(cross(B - A, C - A) >= 0)return ;solve(A, C);solve(C, B);}int main(){while(scanf("%d%d", &n, &m) != EOF){sum = 0;for(int i = 1; i <= n; ++i){scanf("%d%d%d", &a[i], &b[i], &c[i]);sum += a[i];}ans = 1LL << 60;for(int i = 1; i <= n; ++i)f[i] = b[i];point A = gao();for(int i = 1; i <= n; ++i)f[i] = c[i];point B = gao();solve(A, B);cout << ans << endl;}return 0;}
0 0
- HDU 5697 刷题计划
- hdu 5697 刷题计划
- [计划] Leetcode刷题计划
- 【LeetCode】 刷题计划
- 刷题计划
- 寒假刷题计划
- BZOJ 刷题计划
- hdu 2102 A计划
- HDU-2102-A计划
- HDU 2102 A计划
- HDU 2102 A计划
- HDU 2102 A计划
- hdu 2102 A计划
- hdu 2102 A计划
- hdu 2102 A计划
- hdu 2102 A计划
- hdu(2102) A计划
- hdu 2102 A计划
- Rsync 算法
- 20个代码生成器框架
- java 优化
- oracle转mysql总结
- Destoon V6.0手机版伪静态规则不生效的error loading page解决方法
- hdu 5697 刷题计划
- Spring Boot简介
- Android问题集锦
- Hadoop环境配置
- 对象作为方法的参数连续的传递
- 每天刷个算法题20160524:阿克曼函数的递归转非递归解法
- PhoneGap android开发:多媒体API
- 装配线调度
- django学习笔记—(安装django和mysql)