250:

简单题目:

500:

题意:

给定一个矩形,里面要么是"v"表示,要么是".",v表示可能是g,也可能是d,如果是g的话,那么它的哈弗曼距离dis之内如果是v的话,一定是g。求有多少种满足条件的可能数。

思路:

将每一个块分出来,自这一联通块里面,所有的v要么是g,要么d,bfs把所有的快求出来,假设为n,则最后的总数为2^n - 1

View Code

#line 5 "GooseInZooDivTwo.cpp"
#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 Read()  freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)#define M 107
#define N 107
using namespace std;const ll mod = 1000000007;struct node
{int x,y;
}nd;
int n,m;vector<string> tmp;int Abs(int x)
{if (x >= 0) return x;else return (-x);
}
void bfs(int x,int y,int k)
{queue<node>q;nd.x = x; nd.y = y;q.push(nd);int i,j;while (!q.empty()){node u = q.front(); q.pop();for (i = max(0,u.x - k); i <= min(n - 1, u.x + k); ++i){for (j = max(0,u.y - k); j <= min(m - 1,u.y + k); ++j){if (Abs(u.x - i) + Abs(u.y - j) <= k && tmp[i][j] == 'v'){tmp[i][j] = 'g';nd.x = i,nd.y = j;q.push(nd);}}}}
}class GooseInZooDivTwo
{public:int count(vector <string> fd, int dis){int i,j;n = fd.size(); m = fd[0].size();tmp.clear();for (i = 0; i < n; ++i){tmp.push_back(fd[i]);}n = fd.size(); m = fd[0].size();ll cnt = 0;for (i = 0;  i < n; ++i){for (j = 0; j < m; ++j){if (tmp[i][j] == 'v'){cnt++;tmp[i][j] = 'g';bfs(i,j,dis);}}}
//            cout<<cnt<<endl;ll ans = 1;for (i = 0; i < cnt; ++i){ans = ans*2%mod;}return ans - 1;}};// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor// Powered by FileEdit

1000:

题意:
个顶n个段,每个段里面要么有狼,要么没狼,然后给出m个区域间,[l[i],r[i]]表示在区间内至少有一只狼,问满足条件的一共有多少种可能数?

思路:

记忆化搜索DP , dp[i][j]表示到i个段,有j个区间还没有处理, 对于第i个段我们有两种选择要么方狼,要么不放狼。 如果方狼的话,dp[i][j] = dp[i - 1][k] k表示必须多少个区间被处理了。

如果不放的话,要必须满足区间条件。 dp[i][j] += dp[i - 1][j]

View Code

#line 5 "WolfInZooDivTwo.cpp"
#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 Read()  freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)#define M 107
#define N 307
using namespace std;const ll mod = 1000000007;struct node
{int l,r;
}nd[N];ll pow2[N];
ll dp[N][N];
int off[N],cnt;ll DP(int x,int y)
{int i;if (x < 0) return 1;if (dp[x][y] != -1) return dp[x][y];if (y == 0) return (dp[x][y] = pow2[x + 1]);dp[x][y] = 0;for (i = y; i >= 1; --i){if (x > nd[i].r) break;}dp[x][y] += DP(x - 1,i);dp[x][y] %= mod;for (i = y; i >= 1; --i){if (x == nd[i].l) break;}if (i == 0) dp[x][y] += DP(x - 1, y);dp[x][y] %= mod;return dp[x][y];
}
vector<int> getR(string s)
{istringstream is(s);int no;vector<int> rs;while (is >> no){rs.push_back(no);}return rs;
}
class WolfInZooDivTwo
{public:void init(){pow2[0] = 1;for (int i = 1; i <= 300; ++i){pow2[i] = pow2[i - 1]*2%mod;}}int count(int n, vector <string> L, vector <string> R){int i;init();string lstr = "",rstr = "";for (size_t i = 0; i < L.size(); ++i) lstr += L[i];for (size_t i = 0; i < R.size(); ++i) rstr += R[i];vector<int> Ls = getR(lstr);vector<int> Rs = getR(rstr);if (Ls.size() != Rs.size()) puts("BUBIUBYUGB");set<int> sr(Rs.begin(),Rs.end());CL(off,-1);int m = Ls.size();for (i = 0; i < m; ++i) off[Rs[i]] = max(off[Rs[i]],Ls[i]);cnt = 0;set<int>::iterator it = sr.begin();for (; it != sr.end(); ++it){nd[++cnt].l = off[*it];nd[cnt].r = *it;}CL(dp,-1);return DP(n - 1,cnt);}
};

转载于:https://www.cnblogs.com/E-star/archive/2013/05/04/3059327.html

SRM 578 DIV 2相关推荐

  1. Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1

    据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...

  2. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  3. Topcoder SRM 663 DIV 1

    ABBADiv1 题意: 规定两种操作,一种是在字符串的末尾添加A,另一种是在末尾添加B然后反转字符串.现在给你一个起始串,一个终点串,然后问你是否能够通过以上两种操作,从起始串变为终点串. 题解: ...

  4. TopCoder SRM 152 div 2 500point

    这个题目比较简单,自己在纸上写出来给的例子,然后分析一下就会发现规律了:) 我的代码 #include<vector> #include<iostream> using nam ...

  5. 【SRM 716 DIV 1 A】 ConstructLCS

    Problem Statement A string S is a subsequence of a string T if we can obtain S from T by erasing som ...

  6. Codeforces Round #578 (Div. 2)

    Solution A. Hotelier 题意: 对应\(n\)个位置,如果是\(L\),左边第一个为\(0\)的位置变为\(1\),如果是\(R\),右边第一个为\(0\)的位置变为\(1\),如果 ...

  7. Topcoder SRM 628 DIV 2

    被自己蠢哭了.... 250-point problem 国际象棋棋盘上给出两个坐标,问象从一个走到还有一个最少要几步. 黑格象仅仅能走黑格,白格象仅仅能走白格,仅仅要推断两个坐标的颜色是否同样就能推 ...

  8. SRM 587 Div II L3:ThreeColorabilityEasyy

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=12699 这道题目是第一次在比赛的时候做出来的,开始还想用bru ...

  9. SRM 212 Div II Level One: YahtzeeScore

    题目来源:http://community.topcoder.com/stat?c=problem_statement&pm=1692&rd=5858 比较简单. 代码如下: #inc ...

最新文章

  1. 搭建Hexo部署到github上
  2. 机器学习(MACHINE LEARNING) 【周志华版-”西瓜书“-笔记】 DAY4-决策树
  3. ubuntu 16.04 安装PhpMyAdmin
  4. 随手小记:快速适应未必是个好策略
  5. Linux系统调用号表
  6. lsof 详解 (转载)
  7. (转)Objective-C Autorelease Pools(自动释放池)详解
  8. Hadoop--克隆3x虚拟机
  9. Milking Grid poj2185
  10. Spring Boot 返回 XML 数据,一分钟搞定!
  11. mysql手机客户端_图解MySQL索引--B-Tree(B+Tree)
  12. matlab simulink仿真实现电力电子的整流电路
  13. 黑马前端基础-HTML-SE
  14. win10和win8双系统安装
  15. python绘制图形界面(一)
  16. StrStrI 与 strstr
  17. BUUCTF 命令执行/文件包含类型部分wp
  18. 计算机网络安全三个时代,信息网络安全的三个时代是什么
  19. 小米路由器linux界面,小米路由器配置ssh登录方法 | 192.168.1.1登陆页面
  20. 2020双十一成交额 双11各电商平台销售额数据

热门文章

  1. 避开使用XAML的性能陷阱
  2. Entity Framework 4.3尝试体会
  3. matlab 过度曝光,MATLAB:补偿图像处理中的过度曝光/过饱和度
  4. c语言 一元多项式乘法,[内附完整源码和文档] 基于C语言实现的一元多项式的计算...
  5. android 手环获取步数_荣耀手环5 篮球版深度体验:专业数据精细到“毛孔”
  6. Linux概要端口,LINUX中如何查看某个端口是否被占用(转发)
  7. 卷积和池化后特征图的大小~
  8. 3-16Pytorch与随机抽样
  9. adb bugreport保存位置_图文教程:PC利用adb工具通过CMD命令控制手机动作(备忘笔记)...
  10. dockerfile二进制mysql_Dockerfile源码分离部署LNMP(Centos7)