250pt:

水题set处理。

500pt:

题意:

给你一个图,每条边关联的两点为朋友,题目要求假设x的金钱为y,则他的左右的朋友当中的钱数z,取值为y - d <= z <= y + d.求使得任意两点的最大金钱差值,若果是inf输出-1.

思路:
求任意两点的最短的的最大值即可,比赛时不知道哪地方写搓了,直接被系统样例给虐了,老师这么悲剧500有思路能写,老师不仔细哎..

floyd求任意两点的最短距离好写一些。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll __int64
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define keyTree (chd[chd[root][1]][0])
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); #define M 25000
#define N 207 using namespace std; const int inf = 0x7f7f7f7f;
const int mod = ; int f[N][N];
int n;
void floyd()
{
for (int k = ; k <= n; ++k)
{
for (int i = ; i <= n; ++i)
{
for (int j = ; j <= n; ++j)
{
if (f[i][k] != inf && f[k][j] != inf && f[i][j] > f[i][k] + f[k][j])
{
f[i][j] = f[i][k] + f[k][j];
}
}
}
} }
class Egalitarianism
{
public:
int maxDifference(vector <string> isF, int d)
{
n = isF.size();
for (int i = ; i <= n; ++i)
{
for (int j = ; j <= n; ++j) f[i][j] = inf;
}
for (int i = ; i < n; ++i)
{
for (int j = ; j < n; ++j)
{
if (isF[i][j] == 'Y')
{
f[i + ][j + ] = ;
}
}
}
floyd();
int Ma = ;
for (int i = ; i <= n; ++i)
{
for (int j = ; j <= n; ++j)
{
if (i == j) continue;
Ma = max(Ma,f[i][j]);
}
}
if (Ma == inf) return -;
else return Ma*d;
}
};

100pt:

题意:

有n个城市,给出每个城市的类型kind[i]表示i城市属于kind[i]类,然后给出已经发现的类型found[i]表示发现了found[i]类型, 然后给出k求满足有k个城市,并且这k个城市包含了m中已将发现的类型。(k个城市都是从已经发现的类型里面选的) 也即:知道m种数的每种数个数,然后将这些数放入K个箱子里面连,每个箱子只能放一个,要求放完后这k个箱子的数的种数为m

思路:
才开始想用组和公式方看看怎么放,可是那样考虑会有很多重复,而且不好去重。

dp其实很简单,可是就是想不到,弱逼的DP啊。  dp[i][j] 表示一共放了j个箱子,并且放了i种 则dp[i][j] += dp[i - 1][j - p]*c[found[i]][p];

#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll long long
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define keyTree (chd[chd[root][1]][0])
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); #define M 25000
#define N 107 using namespace std; const int inf = 0x7f7f7f7f;
const int mod = ;
ll dp[N][N];
ll c[][];
void init()
{
for (int i = ; i <= ; ++i)
{
c[i][i] = c[i][] = ;
}
for (int i = ; i <= ; ++i)
{
for (int j = ; j < i; ++j)
{
c[i][j] = c[i - ][j] + c[i - ][j - ];
}
}
}
class Excavations2
{
public:
int num[N]; long long count(vector <int> kind, vector <int> found, int K)
{
init();
int n = kind.size();
int m = found.size();
CL(num,); for (int i = ; i < n; ++i) num[kind[i]]++;
CL(dp,); dp[][] = ; for (int i = ; i < m; ++i)
{
for (int j = ; j <= K; ++j)
{
for (int p = ; p <= num[found[i]]; ++p)
{
if (j - p >= )
dp[i + ][j] += dp[i][j - p]*c[num[found[i]]][p];
}
}
}
return dp[m][K];
}
};

TC SRM 584 DIV2的更多相关文章

  1. TC SRM 584 DIV 2

    第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...

  2. TC SRM 663 div2 B AABB 逆推

    AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...

  3. TC SRM 663 div2 A ChessFloor 暴力

    ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...

  4. TC SRM 665 DIV2 A LuckyXor 暴力

    LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...

  5. TC SRM 593 DIV2 1000

    很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...

  6. TC SRM 591 DIV2 1000

    很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...

  7. tc srm 636 div2 500

    100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...

  8. TC SRM 664 div2 B BearPlaysDiv2 bfs

    BearPlaysDiv2 Problem Statement    Limak is a little bear who loves to play. Today he is playing by ...

  9. TC SRM 664 div2 A BearCheats 暴力

     BearCheats Problem Statement    Limak is an old brown bear. Because of his bad eyesight he sometime ...

随机推荐

  1. Android Thread Handler UIHandler demos

    extends:http://blog.csdn.net/superjunjin/article/details/7540064 序效果:为了显示如何用message传值的简单例子 例1,点击按钮,持 ...

  2. nginx软件的编译安装步骤

    1.1 检查软件安装的系统环境 [root@web02 conf]# cat /etc/redhat-release CentOS release 6.8 (Final) [root@web02 co ...

  3. CH5E02 花店橱窗【线性DP】

    5E02 花店橱窗 0x5E「动态规划」练习 背景 xq和他的老婆xz最近开了一家花店,他们准备把店里最好看的花都摆在橱窗里.但是他们有很多花瓶,每个花瓶都具有各自的特点,因此,当各个花瓶中放入不同的 ...

  4. Python高级编程技巧(转)

    译文:http://blog.jobbole.com/61171/ 本文展示一些高级的Python设计结构和它们的使用方法.在日常工作中,你可以根据需要选择合适的数据结构,例如对快速查找性的要求.对数 ...

  5. python之动态参数 *args,**kwargs(聚合,打散--转载

    转自https://www.cnblogs.com/ellisonzhang/p/10243122.html 一.函数的动态参数 *args,**kwargs, 形参的顺序 1.你的函数,为了拓展,对 ...

  6. 两个提高工作效率的神器-Restlet Client和fe助手

    首先是要FQ,百度***或者直接下载蓝灯. 然后安装第一个WEB前端助手:

  7. 循环链表的实现与操作(C语言实现)

    循环链表是还有一种形式的链式存贮结构.它的特点是表中最后一个结点的指针域指向头结点,整个链表形成一个环. 循环链表的操作 1,循环链表的新操作 2, 获取当前游标指向的数据元素 3, 将游标重置指向链 ...

  8. zlib编译安装

    从http://www.zlib.net/下载了最新的源代码 zlib提供了vs sln文件,在zlib-1.2.8\contrib\vstudio\目录有 其中的zlibstat是编译为静态库zli ...

  9. 制造抽象基类--《C++必知必会》 条款33

    抽象类,含有纯虚函数的类,不可以创建对象. 然而,有时我们并不需要某个函数定义为纯虚函数,但是任然希望此类像抽象类一样,不可以创建对象. 方法1:通过确保类中不存在共有构造函数来模拟抽象基类的性质.意 ...

  10. Linux系统——Inotify事件监控工具

    每秒传输文件200个 Rsync放在定时任务中也只是一分钟执行一回,要想达到实时的效果,为防止单点nfs架构故障,再启动一台nfs服务器作为主nfs服务器的备份服务器,此时需要inotify实时同步数 ...