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的更多相关文章

随机推荐

  1. 使用开源的工具解析erspan流量

    Decapsulation ERSPAN Traffic With Open Source Tools Posted on May 3, 2015 by Radovan BrezulaUpdated ...

  2. 设置漂亮的eclipse主题(Theme)风格

    看看这些主题: Eclipse Color Themes 设置步骤: 1.点击help --> Eclipse Marketplace... 2.搜索Color Eclipse Themes 3 ...

  3. 全局组建封装(挂载到vue实例的原型中,通过this访问)

    主题:组建的封装  一:install注册的全局封装(v-grid九宫格组建)               1.九宫格的封装主要有三个api 点击功能 每行个数 是否隐藏边框              ...

  4. lazarus,synedit输入小键盘特殊符号的补丁

    unit synedittextdoublewidthchars2; // fix up chinese symbel width //by steven {$mode objfpc}{$H+} in ...

  5. Spring MVC 数据绑定和表单标签库

    数据绑定是将用户输入绑定到领域模型的一种特性.作用是将 POJO 对象的属性值与表单组件的内容绑定. 数据绑定的好处: 1. 类型总是为 String 的 HTTP 请求参数,可用于填充不同类型的对象 ...

  6. 拼图类APP原型模板分享——简拼

    简拼是一款记录美好.抒写情怀的拼图APP,模板设计风格简约文艺,种类齐全. 此原型模板所用到的组件有标签组.水平分隔线.圆形工具.交互动作有结合标签组实现页面跳转,选择组件触发按钮状态变化等. 此原型 ...

  7. SQL 将一个表中的所有记录插入到一个临时表中

    insert into #tempTable select * from TempTable WHERE + 查询条件

  8. KM匹配板子

    /* gyt Live up to every day */ #include<cstdio> #include<cmath> #include<iostream> ...

  9. hibernate配置文件 连接数据库

    http://jingyan.baidu.com/album/0320e2c1d4dd0b1b87507b38.html?picindex=12

  10. c#的装箱和拆箱及值类型和引用类型

    装箱:它允许根据值类型创建一个对象,然后使用对这新对象的一个引用. int i = 5; object o = i; int j = (int)o; 装箱:运行时将在堆上创建一个包含值5的对象(它是一 ...