大致题意:

有n个向量要你选k个,把这k个向量连起来,画出来的与x轴围成的面积最大

思路:

这个是斜率dp,让斜率大的排在前面,记忆化搜索的时候要加入一个当前高的信息,因为这个向量形成面积不仅和斜率有关还有当前高有关

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
using namespace std;
const int maxn = 60;
struct node{
int x;
int y;
}vec[maxn];
int t,k,n,kase;
int d[maxn][maxn][maxn*maxn];
int vis[maxn][maxn][maxn*maxn];
bool cmp(const node& a,const node& b){
return a.y*b.x>a.x*b.y;
}
int dfs(int id,int cnt,int h){
if(cnt==k) return 0;
if(id==n+1) return 0;
int &ans = d[id][cnt][h];
if(vis[id][cnt][h]==kase) return ans;
ans=0;vis[id][cnt][h]=kase;
ans=max(ans,dfs(id+1,cnt,h));
int add=2*h*vec[id].x+vec[id].x*vec[id].y;
ans=max(ans,dfs(id+1,cnt+1,h+vec[id].y)+add);
return ans;
}
int main(){
cin>>t;
for(kase=1;kase<=t;++kase){
cin>>n>>k;
for(int i=1;i<=n;i++) cin>>vec[i].x>>vec[i].y;
sort(vec+1,vec+n+1,cmp);
printf("Case %d: %d\n",kase,dfs(1,0,0)); }
return 0;
}

UVA12589_Learning Vector的更多相关文章

  1. c++ vector 使用

    1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...

  2. Vector Tile

    Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...

  3. ArrayList、Vector、LinkedList的区别联系?

    1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...

  4. ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量

    当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...

  5. Java中Vector和ArrayList的区别

    首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...

  6. C++使用vector

    #include <iostream> #include <string> #include <vector> using namespace std; void ...

  7. [LeetCode] Flatten 2D Vector 压平二维向量

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  8. C++ 数组array与vector的比较

    转:http://blog.csdn.net/yukin_xue/article/details/7391897 1. array 定义的时候必须定义数组的元素个数;而vector 不需要: 且只能包 ...

  9. vector定义初始化

    头文件 #include<vector> using std::vector; vector<T> v1; vector<T> v2(v1); vector< ...

随机推荐

  1. [HDU 5293]Tree chain problem(树形dp+树链剖分)

    [HDU 5293]Tree chain problem(树形dp+树链剖分) 题面 在一棵树中,给出若干条链和链的权值,求选取不相交的链使得权值和最大. 分析 考虑树形dp,dp[x]表示以x为子树 ...

  2. Anaconda Jupyter WinError2:The system cannot find the file specified

    Traceback (most recent call last): File "C:\Users\builder\Miniconda3\Scripts\conda-build-script ...

  3. 最小生成树,Prim算法实现

    最小生成树 所谓最小生成树,就是一个图的极小连通子图,它包含原图的所有顶点,并且所有边的权值之和尽可能的小. 首先看看第一个例子,有下面这样一个带权图: 它的最小生成树是什么样子呢?下图绿色加粗的边可 ...

  4. Linux Shell 脚本学习第一天: 使用grep 命令,lsusb, ps -ef, 实现树莓派(Debian OS)时检测到依赖的USB设备启动后,启动终端自动执行shell脚本

    1.应用背景: 无人监测的设备,常需要设置应用程序开机启动,程序启动前需要保证调用的设备先启动,运行环境先启动. 2.test.sh部分源码 #!/bin/sh #查看桌面是否启动 while tru ...

  5. 三 Bash Shell 结构

    Bash Shell 程序结构主要有 : 变量设定  内置命令 Shell 语法结构 函数 其他命令行程序构成 例子: [root@localhost ~]# vim test.sh #!/bin/b ...

  6. 【Leetcode周赛】从contest-91开始。(一般是10个contest写一篇文章)

    Contest 91 (2018年10月24日,周三) 链接:https://leetcode.com/contest/weekly-contest-91/ 模拟比赛情况记录:第一题柠檬摊的那题6分钟 ...

  7. Vue列表渲染-变异方法

    Vue 包含一组观察数组的变异方法,变异方法 (mutation method),顾名思义,会改变被这些方法调用的原始数组 所以它们也将会触发视图更新.这些方法如下: push() pop() shi ...

  8. demo板 apt-get install stress

    demo 那个网口 没有绑定mac 大电脑绑定了mac 大电脑上网认证系统:http://1.1.1.2 大电脑mac:6C-4B-90-3C-D5-7B 将demo板的mac改为大电脑mac ifc ...

  9. MySQL-其它整理

    来自:http://www.w3school.com.cn/sql/sql_server.asp 一:基本操作 1)插入 INSERT INTO 表名称 VALUES (值1, 值2,....): I ...

  10. 【leetcode】823. Binary Trees With Factors

    题目如下: Given an array of unique integers, each integer is strictly greater than 1. We make a binary t ...