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. tomcat加载web项目报错:bad major version at offset=6

    分析原因是开发的web项目的java版本高于tomcat使用的java版本,比如我是在java1.6上开发的,但是tomcat使用的java运行环境是1.5,所以会报改错误. 转载博客如下:http: ...

  2. P<0.05就够了?还要校正!校正!3个方法献上

    P<0.05就够了?还要校正!校正!3个方法献上 (2017-01-03 17:55:12) 转载▼   分类: 数理统计 (转  医生科研助手 解螺旋 微信公众号)   当有多组数据要比较时, ...

  3. POJ1659 Frogs' Neighborhood(青蛙的邻居) Havel-Hakimi定理

    Frogs' Neighborhood Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 8729   Accepted: 36 ...

  4. Proxmox Reset Root Password

    http://c-nergy.be/blog/?p=1777 Step 1 – Boot your Proxmox VE machine. In the boot menu screen, you s ...

  5. 【Linux】OpenSSL 安装

    OpenSSL 简介 OpenSSL 是一个安全套接字层密码库,囊括主要的密码算法.常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. OpenSSL 安装 环境:L ...

  6. java JNI 实现原理 (二) Linux 下如何 load JNILibrary

    在博客java JNI (一)虚拟机中classloader的JNILibrary 中讨论了java中的Library 是由classloader 来load的,那我们来看看 classloader是 ...

  7. 23.Xcode中常用的快捷键操作

    1.工程导航器:command+1 浏览文件夹,控制器,图片等 2.显示/隐藏导航器面板:Command+0 隐藏左边工具栏 3.显示/隐藏实用工具面板:Command+Option+0 使用工具面板 ...

  8. 【转】Linux 如何通过命令仅获取IP地址

    一同事的朋友正在参加笔试,遇到这么一个问题让他帮忙解决,结果同事又找到我帮他搞定.真是感慨:通讯发达在某些方面来说,真不知是不是好事啊!题目大致如下所示,一般我们使用ifconfig查看网卡信息,请问 ...

  9. 如何将spring boot项目打包成war包

    一.修改打包形式 在pom.xml里设置 <packaging>war</packaging> 二.移除嵌入式tomcat插件 在pom.xml里找到spring-boot-s ...

  10. Tomcat架构解析(一)-----Tomcat总体架构

    Tomcat是非常常用的应用服务器,了解Tomcat的总体架构以及实现细节,对于理解整个java web也是有非常大的帮助. 一.Server   1.最简单的服务器结构 最简单的服务器结构如图所示: ...