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< ...
随机推荐
- Day6----Python的pyinstall库的使用
Python的pyinstaller库 pyinstaller的安装 介绍:pyinstaller是Python的第三方库,主要用于将Python代码打包成 可执行文件 ,以此达到就算没安装P ...
- [fw]Understanding a Kernel Oops!
An “Oops” is what the kernel throws at us when it finds something faulty, or an exception, in the ke ...
- bzoj1779 [Usaco2010 Hol]Cowwar 奶牛战争(网络流)
1779: [Usaco2010 Hol]Cowwar 奶牛战争 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 302 Solved: 131[Sub ...
- Helm教程
1.概述 Helm是k8s的包管理工具,类似Linux系统常用的 apt.yum等包管理工具. 使用helm可以简化k8s应用部署 2.基本概念 Chart:一个 Helm 包,其中包含了运行一个应用 ...
- AJAX 获取Servlet文件路径
下面均不行: xmlRes.open("get","edu/hust/ajax/TestServlet",true); xmlRes.open("ge ...
- NGUI技能CD效果制作(sprite的type:filled)
一,我们先添加一个sprite,改名为skill.给当前skill添加图片,然后再sprite下添加一个sprite和一个label,结果如下 二现在我们来设置skill下的sprite,给他设置一个 ...
- 20180209-json&pickle&shelve模块
什么是序列化? 序列化就是把内存里的数据类型转成字符串,以使其能够存储到硬盘中或在网络中传输到远程,因为硬盘和网络传输时只接收bytes 用于序列化的两个模块 1. json,用于字符串和python ...
- ajax中的application/x-www-form-urlencoded中的使用[转]
一,HTTP上传的基本知识 在Form元素的语法中,EncType表明提交数据的格式 用 Enctype 属性指定将数据回发到服务器时浏览器使用的编码类型.下边是说明: application/x-w ...
- A Tutorial on Using the ALSA Audio API
A Tutorial on Using the ALSA Audio API This document attempts to provide an introduction to the ALSA ...
- vue,一路走来(13)--vue微信分享
vue微信分享 今天记录一下vue微信分享. 1.先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”.这个不多说,见文档,只有绑定了才能进行下一步的动作 2.需要引入js文件 ...