uva 12589——Learning Vector
来源:互联网 发布:写作文网络词语 编辑:程序博客网 时间:2024/05/22 09:40
题意:输入n个向量(x,y),要求选出k个,从(0,0)开始画,使得画出来的折线与x轴围成的面积最大。输出面积的二倍。
思路:01背包,dp[i][j]表示y的坐标为i且已经选了j个点的最大面积,然后10包选当前点和不选当前点的最大值。
code:
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef long double ld;const int INF=0x3fffffff;const int inf=-INF;const int N=1000000;const int M=55;const int mod=1000000007;const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))#define cpy(x,a) memcpy(x,a,sizeof(a))#define ft(i,s,n) for (int i=s;i<=n;i++)#define frt(i,s,t) for (int i=s;i>=t;i--)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define lowbit(x) (x&-x)#define pii pair<int,int>#define mk make_pair#define IN freopen("in.txt","r",stdin);#define OUT freopen("out.txt","w",stdout);struct node{ int x,y; bool operator <(const node& b)const{ return b.x*y>b.y*x; }}g[M];int T,n,k;int dp[M*M][M];int main(){ scanf("%d",&T); ft(ca,1,T){ scanf("%d %d",&n,&k); ft(i,0,n-1) scanf("%d %d",&g[i].x,&g[i].y); sort(g,g+n);cls(dp,-0x3f);dp[0][0]=0; ft(i,0,n-1) frt(j,M*M-1,0) frt(q,k-1,0){ if (dp[j][q]>=0) dp[j+g[i].y][q+1]=max(dp[j+g[i].y][q+1],dp[j][q]+(g[i].y+2*j)*g[i].x); } int ans=0; ft(i,0,M*M-1) ans=max(ans,dp[i][k]); printf("Case %d: %d\n",ca,ans); }}
0 0
- uva 12589——Learning Vector
- UVa 12589 Learning Vector
- uva 12589 Learning Vector
- UVa 12589 Learning Vector
- Uva-12589 Learning Vector
- uva 12589 learning vector
- UVA 12589 Learning Vector
- Learning Vector - UVa 12589 dp
- UVA - 12589(learning vector dp)
- [UVA 12589]Learning Vector[DP]
- UVA 12589 Learning Vector 解题报告
- UVA 12589 Learning Vector(DP)
- Learning Vector UVA
- Machine Learning—Support Vector Machines(1)
- Learning Vector
- UVA 11991 Easy Problem from Rujia Liu?——Vector
- Andrew Ng《Machine Learning》第七讲——支持向量机SVM(Support Vector Machine)
- Machine Learning—Support Vector Machines(2)Kernels非线性支持矢量机学习算法
- HDU2602(简单背包问题)
- 远程WEB控制MP3播放器设计(基于mini2440)
- LibSVM 在matlab中的使用--Rachel Zhang的专栏
- 二叉树代数求解表达式
- C#学习笔记——LINQ数据访问
- uva 12589——Learning Vector
- 初见WCF
- Spring源码导入Eclipse图文教程
- linux windows Tomcat内存优化
- WCF之 契约
- 跨浏览器按钮兼容+封装浏览器的按键
- 排序算法(二):归并排序
- ARMv8 内存管理架构.学习笔记
- 程序员选择公司的8个标准!