SRM476
250pt
题意:饲养N<=50只Badgers,每只食量是X[i],当没看到别的一只Badgers吃东西时,它的食量就会增加Y[i],现在一共用P的粮食,问最多能养的起多少只獾。
思路:枚举一下养多少只。那么接下来贪心即可。
code:
#line 7 "Badgers.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class Badgers
{
public:
int feedMost(vector <int> a, vector <int> b, int totalFood)
{
int n = a.size();
vector<int> c;
for (int i = n; i > ; --i){
c.clear();
for (int j = ; j < n; ++j)
c.PB(a[j] + (i - ) * b[j]);
sort(c.begin(), c.end());
int sum = ;
for (int j = ; j < i; ++j)
sum += c[j];
if (sum <= totalFood) return i;
}
return ;
}
};
500pt
题意:某社交网站上有N<=36个人,每个人的页面只会随机显示K<=36个好友,如果好友数不足K则全部显示。现在0号人先从自己的页面开始,每次访问一个还没访问过的好友,然后在访问该好友的好友中自己还没访问过的自己的好友。也就是说他只会访问自己的好友,且每个好友只会访问一次。在知道所有好友关系的情况下,问在最优策略下0号人有多少的概率能访问到他的所有好友。
思路:注意到字符串长度最多36,并且中间有空格,那么每个人最多也就15个好友,并且每次只会访问他还没访问的好友。
所以动态规划+枚举即可
dp[i][mask]表示访问0的第i个好友,并且访问好友的情况为mask情况下的最优解。
统计时相对麻烦点。要按概率第一高,第二的顺序枚举。。具体看代码吧
code:
#line 7 "FriendTour.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
#define M0(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define two(i) (1 << i)
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
vector<int> g[];
double dp[ << ][];
double c[][];
bool vis[ << ][];
int P[];
class FriendTour
{
public:
int n, m, k;
void make_friend(int k, string S){
g[k].clear();
// if (k == 0) g[k].push_back(k);
int len = S.size();
int tmp = ;
for (int i = ; i < len; ++i)
if (S[i] == ' '){
g[k].push_back(--tmp);
tmp = ;
} else tmp = tmp * + S[i] - ;
if (tmp) g[k].push_back(--tmp); }
void dfs(int S, int L){
if (vis[S][L]) return;
vis[S][L] = true;
dp[S][L] = ;
if (S == two(n+)-){ dp[S][L] = 1.0; return; }
int x = ;
if (L > ) x = g[][L-];
vector<double> v;
for (int i = ; i < g[x].size(); ++i){
if (P[g[x][i]] == || (S & two(P[g[x][i]]))) continue;
dfs(S | two(P[g[x][i]]), P[g[x][i]]);
v.push_back(dp[S | two(P[g[x][i]])][P[g[x][i]]]);
}
sort(v.begin(), v.end(), greater<double>());
int total = g[x].size(), d = min(k, total);
// double c1;
for (int i = ; i < v.size(); ++i){
// c1 = v[i];
dp[S][L] += v[i] * c[total-i-][d-];
}
dp[S][L] /= c[total][d];
}
double tourProbability(vector <string> friends, int K)
{
m = friends.size();
for (int i = ; i < m; ++i) make_friend(i, friends[i]);
for (int i = ; i <= ; ++i){
c[i][] = 1.0;
for (int j = ; j <= i; ++j)
c[i][j] = c[i-][j] + c[i-][j-];
}
// M0(dp);
M0(vis);
n = g[].size();
// cout << n << endl;
M0(P);
for (int i = ; i < n; ++i) P[g[][i]] = i + ;// cout << g[0][i] << endl;
k = K;
dfs(, );
return dp[][];
}
};
SRM476的更多相关文章
随机推荐
- Android.Tools.Summary
Android平台上工具的总结 每个工具的详细使用和深入理解参考每个工具相关的blog. 1. Android SDK中提供的工具 http://developer.android.com/tools ...
- MySQL 检索数据及提高检索速度的方法
检索数据 mysql> SELECT [DISTINCT] 表名.列名,表名.列名,表名.列名 -- 使用通配符*表示所有列 DISTINCT表示返回不同的值 -> FROM 数据库名.表 ...
- 繁体简体转化_langconv.py
from copy import deepcopyimport re try: import psyco psyco.full()except: pass try: from zh_wiki impo ...
- 跟我学Spring Boot(三)Spring Boot 的web开发
1.Web开发中至关重要的一部分,Web开发的核心内容主要包括内嵌Servlet容器和SpringMVC spring boot 提供了spring-boot-starter-web 为web开发提 ...
- .net从网络接口地址获取json,然后解析成对象(二)
整理代码,这是第二种方法来读取json,然后反序列化成对象的,代码如下: public static Order GetOrderInfo(string _tid, string _orderNo) ...
- 使用Python完成表格自动输入
看了看<Python编程快速上手>,写了个小脚本完成12306登录数据的自动输入.如下: 1 import webbrowser 2 import pyautogui 3 import t ...
- OneZero_Aphla发布总结以及自己的体会
Aphla发布正式结束了.清明时节,总要祭奠点什么. 以下是这一周的燃尽图. 可以发现,并没有燃尽.所以OneZero的Aphla发布失败了. 失败原因有至少以下三点: 1.组长分配任务存在隐患,高风 ...
- 42.OC中instancetype与id的区别
区别: 在ARC(Auto Reference Count)环境下: instancetype用来在编译期确定实例的类型,而使用id的话,编译器不检查类型,运行时检查类型 在MRC(Manual Re ...
- iOS知识基础篇--@property,@synthesize, nonatomic,atomic,strong,weak,copy,assign,retain详解
一.@property 这个关键词的唯一作用就是声明getter.setter方法接口. 二.@synthesize 实现setter.getter方法,找不到实例变量则主动创建一个. 三.nonat ...
- 定时调度系列之Quartz.Net详解(转)
出处:https://www.cnblogs.com/yaopengfei/p/9216229.html 一. 背景 我们在日常开发中,可能你会遇到这样的需求:"每个月的3号给用户发信息,提 ...