SRM 565

目前只是粗略看了一下division 2 的前两题, 还是蛮简单的。

problem1:按照题意叙述来就行了。。。

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class ValueHistogram {
public:
	vector <string> build(vector <int>);
};

vector <string> ValueHistogram::build(vector <int> values) {
	int len = values.size();
	int count[11], max_number=0;
	memset(count, 0, sizeof(count));
	
	//count values
	for(int i=0; i<len; i++){
		count[values[i]]++;
		max_number = max(max_number, count[values[i]]);
	}
	
	//initial the vector
	vector<string> res(max_number + 1);
	for(int i=0; i<=max_number; i++){
		string str = "..........";
		res[i] = str;
	}
	//change the vector contents to get the results
	for(int i=0; i<10; i++){
		for(int j=0; j<count[i]; j++){
			res[max_number-j][i] = 'X';
		}
	}
	return res;
}

//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!

probelm2:也不是很难,状态数并不多,因此进行回溯搜索就可以了。

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class MonstersValley2 {
public:
	int res, len;
	vector<int> d, p;
	int minimumPrice(vector <int>, vector <int>);
	void rec(int step, int cost, long long sum);
};

void MonstersValley2::rec(int step, int cost, long long sum){
	//boundary of recurrence
	if(step == len){
		res = min(res, cost);
		return;
	}
	if(cost >= res)
		return;
	//can only bribe the monster
	if(sum < d[step]){
		rec(step+1, cost+p[step], sum+d[step]);		
	}
	else{
		rec(step+1, cost, sum);
		rec(step+1, cost+p[step], sum+d[step]);
	}
	return;
}

int MonstersValley2::minimumPrice(vector <int> dread, vector <int> price) {
	d = dread, p = price;
	len = dread.size();
	res = len*2;
	rec(1, price[0], dread[0]);
	return res;
}

//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值