UVA12589_Learning Vector
大致题意:
有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的更多相关文章
- c++ vector 使用
1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...
- Vector Tile
Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...
- ArrayList、Vector、LinkedList的区别联系?
1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...
- ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量
当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...
- Java中Vector和ArrayList的区别
首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...
- C++使用vector
#include <iostream> #include <string> #include <vector> using namespace std; void ...
- [LeetCode] Flatten 2D Vector 压平二维向量
Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...
- C++ 数组array与vector的比较
转:http://blog.csdn.net/yukin_xue/article/details/7391897 1. array 定义的时候必须定义数组的元素个数;而vector 不需要: 且只能包 ...
- vector定义初始化
头文件 #include<vector> using std::vector; vector<T> v1; vector<T> v2(v1); vector< ...
随机推荐
- Java并发编程:Concurrent锁机制解析
Java并发编程:Concurrent锁机制解析 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: # ...
- 【JMeter4.0】二、JMeter4.0安装与配置
二.安装配置JMeter jmeter是一个纯java工具,因此,JDK必不可少,现在最新版的jmeter是4.0,建议使用1.8及以上的JDK安装配置JDK,如没有,请见:[JMeter4.0]一. ...
- Windows程序设计--(五)绘图基础
5.1 GDI的结构 图形设备接口(GDI:Graphics Device Interface)是Windows的子系统,它负责在视讯显示器和打印机上显示图形. 5.2 设备环境 5.2.1 获取设备 ...
- 安装weblogic界面安装
如果中间有任何问题请联系作者:291562721 界面安装weblogic首先 需要工具: 链接:https://pan.baidu.com/s/1x3uYxsnycjT2Xi2TOTbDdQ 提取码 ...
- 监控软件之open-falcon
一.open-falcon介绍 1)中文社区介绍 http://book.open-falcon.org/zh_0_2/intro/ 参照文档: https://www.cnblogs.com/LAl ...
- 奇异值分解基础(SVD)
最近要了解一下Incremental PCA的一些知识,然后看到一篇论文里面讲到了SVD(奇异值分解),奈何自己以前没有把机器学习的课好好上,现在很多东西还是要补回来.所以,我就想了解一些SVD的基础 ...
- node留言板开发————node.js
各位需要的话可以下载去看一下. 源码下载链接:https://download.csdn.net/download/weixin_41018304/11833778
- Opencv识别图中人脸
#!/usr/bin/python #coding=utf-8 # 识别图片中的人脸 import face_recognition jobs_image = face_recognition.loa ...
- ubuntu下安装c man文档
http://www.mirrorservice.org/sites/sourceware.org/pub/gcc/libstdc%2b%2b/doxygen/ 下载 http://www.mirro ...
- 2019-9-8-WPF-渲染原理
title author date CreateTime categories WPF 渲染原理 lindexi 2019-9-8 10:40:0 +0800 2018-7-15 16:2:47 +0 ...