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. DtCMS 在IIS7.0 下之伪静态

    1)首先新建一个应用程序池,名称任意,比如:nettest,托管管道模式先暂时设置为集成模式,等下面的一系列设置完成之后再设置成经典模式: 2)部署好站点,并将此站点的应用程序池设置为nettest; ...

  2. poj 3624 && hdu 2955(背包入门)

    http://poj.org/problem?id=3624 背包中最基础的01背包,大意是有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使价值总 ...

  3. iOS.PrototypeTools

    1. iPhone/iPad 原型工具 http://giveabrief.com/ 2. proto.io https://proto.io/ 3. Origami http://facebook. ...

  4. iOS 3D Touch功能

    新的触摸体验——iOS9的3D Touch 一.引言 在iphone6s问世之后,很多果粉都争先要体验3D Touch给用户带来的额外维度上的交互,这个设计之所以叫做3D Touch,其原理上是增加了 ...

  5. Luogu 1273 有线电视网 - 树形背包

    Description 树形背包, 遍历到一个节点, 枚举它的每个子节点要选择多少个用户进行转移. Code #include<cstring> #include<cstdio> ...

  6. sqlalchemy根据数据库结构生成映射的实体

    # !/usr/bin/python # -*- coding: UTF-8 -*- from sqlalchemy import * from sqlalchemy.orm import sessi ...

  7. oracle导出expdp导入impdp

    conn sys/password as sysdba;创建用户test1CREATE USER test1 IDENTIFIED BY "pass1";GRANT CONNECT ...

  8. RSS工具关注期刊,方便快速获取及时大量的文献信息

    第一步: 第二步: 第三步: RSS : 很好的一个东西,到了中国,咋就水土不服了呢...

  9. android检测手机是否安装某个app

    public static boolean isAvilible(Context context, String packageName){ //获取packagemanager final Pack ...

  10. SPRING 集成 KAFKA 发送消息

    准备工作 1.安装kafka+zookeeper环境 2.利用命令创建好topic,创建一个topic my-topic 集成步骤 1.配置生产者 <?xml version="1.0 ...