时间限制: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. vuex相关(actions和mutation的异曲同工)

    vuex说明: Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 包含的内容: state: ...

  2. 在git提交时忽略已提交过或从线上拉取下来但本地已修改的文件

    一.忽略: git update-index --assume-unchanged [file-path] 命令中的file-path 就是需要忽略提价的文件的路径 例子: git update-in ...

  3. Sax解析xml文档

    测试的xml数据: <?xml version="1.0" encoding="utf-8" ?> <note> <to>G ...

  4. 配置Django+mysql+pydev(x64)

    mysqldb需要安装64位的(http://ishare.iask.sina.com.cn/f/21839771.html),否则出现 import _mysql ImportError: DLL ...

  5. 3.2.8 sed 的运作

        sed 的工作方式相当直接.命令行上的每个文件会依次打开与读取.如果没有文件,则使用标准输入,文件名“-”(单个破折号)可用于表示标准输入.       [many@avention Desk ...

  6. BBS+Blog项目流程及补充知识点

    项目流程: 1. 产品需求 (1)基于用户认证组件和Ajax实现登陆验证(图片验证码) (2)基于forms组件和Ajax实现注册功能 (3)设计系统首页(文章列表渲染) (4)设计个人站点页面 (5 ...

  7. 前端开发:JQuery(1)

    JQuery DOM文档加载的步骤: 1. 解析HTML结构: 2. 加载外部脚本和样式: 3. 解析并执行脚本代码: 4. DOM树构建完成: 5. 加载图片等外部文件: 6. 页面加载完成: JS ...

  8. jQuery的观察者模式详解 转载

    jQuery的观察者模式详解 投稿:hebedich 本文主要是介绍了jQuery中on方法及trigger方法,以及围绕这个方法来体验的观察者模式,是篇非常不错的文章,对我们理解观察者模式很有帮助. ...

  9. cogs——2419. [HZOI 2016]公路修建2

    2419. [HZOI 2016]公路修建2 ★☆   输入文件:hzoi_road2.in   输出文件:hzoi_road2.out   简单对比时间限制:1 s   内存限制:128 MB [题 ...

  10. MongoDB学习day01--非关系型数据库

    1.数据库和文件的主要区别: 1.1数据库有数据库表/行和列的概念,让我们存储操作数据方便 1.2数据库提供了方便的接口,让java.php..net.nodejs很方便的实现增删改查 2.NoSQL ...