时间限制: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. 用PHP的GD库画五星红旗来玩玩

    1 header("Content-Type:image/jpeg"); $img=imagecreatetruecolor(999,667); $color=imagecolor ...

  2. centos passwo文件被删除

    错误提示 该问题一般由/etc/passwd被清空,删除,移动,改名等造成,需要通过救援模式恢复,操作步骤如下 真实环境已经解决,这里使用vmware模拟.光盘启动,选择救援模式: 语言选择,键盘布局 ...

  3. python中正则表达式与模式匹配

    一.前言 在之前找工作过程中,面试时经常被问到会不会python,懂不懂正则表达式.心里想:软件的东西和芯片设计有什么关系?咱也不知道因为啥用这个,咱也不敢问啊!在网上搜索到了一篇关于脚本在ASIC领 ...

  4. eclipse导入项目时报错不能运行问题的一个记录

    一直用学校的云桌面,但是还是有一些地方不是很方便,必须要校园网以及需要离线保存: 碰到的问题:重新安装和云桌面一样版本的jdk9.0.4,以及tomcat9.0.12,以及eclipse-oxygen ...

  5. 慕课笔记利用css进行布局【混合布局练习】

    通过学习div的布局,以一个简单的内容管理网站的布局为例子,用div+css进行简单的网页布局,加深学印象: <html> <head> <title>CSS+di ...

  6. 【Eclipse】eclipse中设置tomcat启动时候的JVM参数

    主要通过以下的几个jvm参数来设置堆内存的: -Xmx512m 最大总堆内存,一般设置为物理内存的1/4 -Xms512m 初始总堆内存,一般将它设置的和最大堆内存一样大,这样就不需要根据当前堆使用情 ...

  7. 基于端口的信息探测-portscan-1.0

    http://www.tiaozhanziwo.com/archives/174.html

  8. Path Sum(参考别人,二叉树DFS)

    Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...

  9. Ubuntu 16.04安装SwitchHosts

    下载: https://github.com/oldj/SwitchHosts/releases 解压: unzip SwitchHosts-linux-x64_v3.3.6.5287.zip 移动: ...

  10. rsyslogd系统日志服务总结

    简单介绍 syslog系统日志服务协议,标准出来的比较晚 用于记录系统日志或者用户程序产生的日志 采用C/S架构,本地可以通过socket和syslogd守护进程通讯,远程通过TCP/UDP协议通信, ...