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. JQuery Deferred 对象

    http://www.ruanyifeng.com/blog/2011/08/a_detailed_explanation_of_jquery_deferred_object.html <jQu ...

  2. python下的MySQL数据库编程

    https://www.tutorialspoint.com/python/python_database_access.htm if you need to access an Oracle dat ...

  3. p值还是 FDR ?

    p值还是 FDR ? 差异分析 如何筛选显著性差异基因,p value, FDR 如何选 经常有同学询问如何筛选差异的基因(蛋白).已经计算了表达量和p value值,差异的基因(蛋白)太多了,如何筛 ...

  4. Mac下配置域名和网站测试环境

    一.在 /etc/hosts   下配置相关域名 1, control+space  打开spotlight, 搜索“terminal” 2, 打开Terminal 3, 在terminal界面中输入 ...

  5. Spring MVC(一)Servlet 2.x 规范在 Spring MVC 中的应用

    Spring MVC(一)Servlet 2.x 规范在 Spring MVC 中的应用 Spring 系列目录(https://www.cnblogs.com/binarylei/p/1019869 ...

  6. windows 10 开发学习资料,Windows-universal-samples学习笔记系列一:App settings

    windows 10 通用代码范例: https://github.com/Microsoft/Windows-universal-samples 相关视频:https://mix.office.co ...

  7. Maven手动将jar包放入本地仓库

    mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面 ...

  8. 2019.01.19 bzoj4592: [Shoi2015]脑洞治疗仪(ODT)

    传送门 ODT水题. 支持区间01赋值,区间填补(把区间[l,r][l,r][l,r]从左往右数kkk个1都变成0),区间查询最长连续1个数. 思路: 区间填补操作感觉不是很好弄,写线段树的神仙可以套 ...

  9. UOJ 117 欧拉回路(套圈法+欧拉回路路径输出+骚操作)

    题目链接:http://uoj.ac/problem/117 题目大意: 解题思路:先判断度数: 若G为有向图,欧拉回路的点的出度等于入度. 若G为无向图,欧拉回路的点的度数位偶数. 然后判断连通性, ...

  10. Echarts的使用方法

    效果图: 1. 在echarts官网下载包,解压后,将文件Echarts\echarts-2.2.7\echarts-2.2.7\doc\example\www\js\echarts.js文件拷贝,放 ...