时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

A company plans to recruit some new employees. There are N candidates (indexed from 1 to N) have taken the recruitment examination. After the examination, the well-estimated ability value as well as the expected salary per year of each candidate is collected by the Human Resource Department.

Now the company need to choose their new employees according to these data. To maximize the company's benefits, some principles should be followed:

1. There should be exactly X males and Y females.

2. The sum of salaries per year of the chosen candidates should not exceed the given budget B.

3. The sum of ability values of the chosen candidates should be maximum, without breaking the previous principles. Based on this, the sum of the salary per year should be minimum.

4. If there are multiple answers, choose the lexicographically smallest one. In other words, you should minimize the smallest index of the chosen candidates; If there are still multiple answers, then minimize the second smallest index; If still multiple answers, then minimize the third smallest one; ...

Your task is to help the company choose the new employees from those candidates.

输入

The first line contains four integers N, X, Y, and B, separated by a single space. The meanings of all these variables are showed in the description above. 1 <= N <= 100, 0 <= X <= N, 0 <= Y <= N, 1 <= X + Y <= N, 1 <= B <= 1000.

Then follows N lines. The i-th line contains the data of the i-th candidate: a character G, and two integers V and S, separated by a single space. G indicates the gender (either "M" for male, or "F" for female), V is the well-estimated ability value and S is the expected salary per year of this candidate. 1 <= V <= 10000, 0 <= S <= 10.

We assure that there is always at least one possible answer.

输出

On the first line, output the sum of ability values and the sum of salaries per year of the chosen candidates, separated by a single space.

On the second line, output the indexes of the chosen candidates in ascending order, separated by a single space.

样例输入
4 1 1 10
F 2 3
M 7 6
M 3 2
F 9 9
样例输出
9 9
1 2

思路,动态规划,男女分别求出在某个salary i,选择j个男/女的最小花费(转移方程比较简单就不写了,可以滚动数组求),最后枚举男的salary i和女的salary j 找最大值即可。剩下的就是细节,保证找出满足题目要求的最优解。应该不会超时。

代码没有提交验证,只是写了自己的思路。

 #include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll; #define inf 0x7fffffff #define read freopen("in.txt","r",stdin) #define N 111
#define B 1111
int dp[][][N][B];
int tr[][N][B];
int ss[N];
vector<int>v1,v2;
int main()
{
//read;
int n,x,y,b;
while (~scanf("%d%d%d%d\n",&n,&x,&y,&b))
{
memset(dp,-,sizeof(dp));
for (int i = ; i < ; ++i)
for (int j = ; j < ; ++j)
dp[i][j][][] = ;
char g;
int v,s;
int c1 = ,c2 = ;
for (int i = ; i <= n; ++i)
{
scanf("%c%d%d\n",&g,&v,&s);
ss[i] = s;
int c,f,r;
if (g == 'M')
{
c1++;
r = ;
c = c1;
}
else
{
c2++;
r = ;
c = c2;
}
f = c%;
for (int j = ; j <= c; ++j)
for (int k = ; k <= b; ++k)
{
dp[r][f][j][k] = dp[r][-f][j][k];
if (k >= s && ~dp[r][-f][j-][k-s] && dp[r][-f][j-][k-s] + v > dp[r][f][j][k])
{
dp[r][f][j][k] = dp[r][-f][j-][k-s] + v;
tr[r][j][k] = i;
}
}
}
int ans = ,cost = inf;
for (int i = ; i <= b; ++i)
for (int j = ; j <= b -i ; ++j)
{
if (dp[][c1%][x][i] == - || dp[][c2%][y][j] == -)
continue;
int ta =dp[][c1%][x][i] + dp[][c2%][y][j];
int tb = i + j;
if (ans < ta || (ans == ta && tb < cost))
{
ans = ta,cost = tb;
v1.clear();
int t1 = x, t2 = i;
while (tr[][t1][t2])
{
v1.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
t1 = y, t2 = j;
while( tr[][t1][t2])
{
v1.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
sort(v1.begin(),v1.end());
}
else if (ans == ta && cost == tb)
{
v2.clear();
int t1 = x, t2 = i;
while (tr[][t1][t2])
{
v2.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
t1 = y, t2 = j;
while( tr[][t1][t2])
{
v2.push_back(tr[][t1][t2]);
t1--;
t2 -= ss[tr[][t1][t2]];
}
sort(v2.begin(),v2.end());
bool flag = false;
for (size_t i = ; i < v1.size(); ++i)
if (v1[i] > v2[i])
{
flag = true;
break;
}
if (flag)
{
v1.clear();
for (size_t i = ; i < v2.size(); ++i)
v1.push_back(v2[i]);
}
}
}
printf("%d %d\n",ans,cost);
for (size_t i = ; i < v1.size(); ++i)
{
if (i)
printf(" ");
printf("%d",v1[i]);
}
printf("\n"); }
return ;
}

另外求C题[Islands Travel]思路……,不会做……。以下:

时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

There are N islands on a planet whose coordinates are (X1, Y1), (X2, Y2), (X3, Y3) ..., (XN, YN). You starts at the 1st island (X1, Y1) and your destination is the n-th island (XN, YN). Travelling between i-th and j-th islands will cost you min{|Xi-Xj|, |Yi-Yj|} (|a| denotes the absolute value of a. min{a, b} denotes the smaller value between a and b) gold coins. You want to know what is the minimum cost to travel from the 1st island to the n-th island.

输入

Line 1: an integer N.

Line 2~N+1: each line contains two integers Xi and Yi.

For 40% data, N<=1000,0<=Xi,Yi<=100000.

For 100% data, N<=100000,0<=Xi,Yi<=1000000000.

输出

Output the minimum cost.

样例输入
3
2 2
1 7
7 6
样例输出
2

微软2016校园招聘在线笔试 [Recruitment]的更多相关文章

  1. 微软2016校园招聘在线笔试-Professor Q's Software

    题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new softw ...

  2. 微软2016校园招聘在线笔试第二场 题目1 : Lucky Substrings

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 A string s is LUCKY if and only if the number of different ch ...

  3. 微软2016校园招聘在线笔试 B Professor Q's Software [ 拓扑图dp ]

    传送门 题目2 : Professor Q's Software 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Professor Q develops a new s ...

  4. 题目3 : Spring Outing 微软2016校园招聘在线笔试第二场

    题目3 : Spring Outing 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 You class are planning for a spring outin ...

  5. 微软2016校园招聘在线笔试之Magic Box

    题目1 : Magic Box 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 The circus clown Sunny has a magic box. When ...

  6. hihocoder 1288 : Font Size (微软2016校园招聘4月在线笔试)

    hihocoder 1288 笔试第一道..wa了好几次,也是无语..hihocoder错了不会告诉你失败的时候的测试集,这样有时候就很烦.. 遍历所有的字体,从min(w,h)开始逐渐变小开始遍历. ...

  7. 微软2016校园招聘4月在线笔试 A FontSize

    题目链接:http://hihocoder.com/problemset/problem/1288 分析:题目中所求的是最大的FontSize(记为S),其应该满足P*[W/S]*[H/S] > ...

  8. 微软2016校园招聘4月在线笔试 ABC

    题目链接:http://hihocoder.com/contest/mstest2016april1/problems 第一题:输入N,P,W,H,代表有N段文字,每段有ai个字,每行有⌊W/S⌋个字 ...

  9. 微软2016校园招聘4月在线笔试 hihocoder 1289 403 Forbidden

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描写叙述 Little Hi runs a web server. Sometimes he has to deny acces ...

随机推荐

  1. java枚举中常见的7中用法

    2016年08月11日 11:14:45 李学凯  原文链接https://blog.csdn.net/qq_27093465/article/details/52180865 JDK1.5引入了新的 ...

  2. Matlab学习笔记(二)

    二.MATLAB基础知识 (二)数值.变量和表达式 命名规则: 变量名对大小写敏感,即区分大小写 变量名必须以字母开头,后面可以采用数字.下划线和字母,但不能使用空格.标点符号和运算符 变量名最长可以 ...

  3. poj1984并查集的相对偏移

    #include<stdio.h>//典型题 #include<math.h> #define N 40010 struct node { int x,y,z; }pre[N] ...

  4. node的express框架,核心第三方模块body-parser 获取我们所有post请求传过来数据

    - 安装 body-parser模块- npm install body-parser -S - 调用- let bodyParser=require('body-parser'); - 设置中间件- ...

  5. android开发里跳过的坑——“org.apache.http.message.BasicHeaderValueFormatter.INSTANCE”错误

    在android4.4.2的系统里,写了一个系统应用,其中有一个功能是通过表单上传图片的,使用了httpclient-4.5.3.jar httpmime-4.5.3.jar httpcore-4.4 ...

  6. Linux下汇编语言学习笔记45 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  7. Web 后端编程的几个关键点(总结中...)

    基础 服务端结构 服务器如何部署,负载均衡,代理技术,如何向B端提供服务? 分布式架构 与前端界面的交互形式 数据 CURD 表之间的关联 较为棘手 如何将一对多 多对多的概念进行 面向对象 描述 前 ...

  8. Pagodas 等差数列

    nn pagodas were standing erect in Hong Jue Si between the Niushou Mountain and the Yuntai Mountain, ...

  9. 洛谷 P1708 天然气井

    P1708 天然气井 题目描述 Mary试图控制成都的天然气市场.专家已经标示出了最好的天然气井和中转站在成都的地图.现在需要将中转站和天然气井连接起来.每个中转站必须被连接到正好一个钻油井,反之亦然 ...

  10. Memcached的几种Java客户端(待实践)

    其实现在来尝试Memcached的客户端估计会有点过气,因为现在大势基本都在Redis那边. Memcached Client目前有3种: Memcached Client for Java(已经停止 ...