A.数据量很小,直接爆搞。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cmath>
  6. #include <cstring>
  7. #include <queue>
  8. #include <set>
  9. #include <vector>
  10. #include <stack>
  11. #include <map>
  12. #include <iomanip>
  13. #define PI acos(-1.0)
  14. #define Max 2505
  15. #define inf 1<<28
  16. #define LL(x) ( x << 1 )
  17. #define RR(x) ( x << 1 | 1 )
  18. #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
  19. #define ll long long
  20. #define mem(a,b) memset(a,b,sizeof(a))
  21. #define mp(a,b) make_pair(a,b)
  22. #define PII pair<int,int>
  23. using namespace std;
  24.  
  25. int a[111] ;
  26. int num[11111] ;
  27. int main() {
  28.  
  29. int n ;
  30. cin >> n ;
  31. int ans = 0 ;
  32. for (int i = 1 ; i <= n ;i ++ ){
  33. cin >> a[i] ;
  34. num[i] = num[i - 1] + a[i] ;
  35. }
  36. ans = num[n] - 1 ;
  37. for(int i = 1; i <= n; ++i ){
  38. for(int j = 1; j <= i; ++ j){
  39. int sum = num[n] - 2 * ( num[i] - num[j-1] ) + ( i - j + 1 );
  40. ans = max(sum ,ans) ;
  41. }
  42. }
  43. cout << ans << endl;
  44.  
  45. return 0 ;
  46. }

B,直接打个素数表,然后输出前N个素数就可以了。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cmath>
  6. #include <cstring>
  7. #include <queue>
  8. #include <set>
  9. #include <vector>
  10. #include <stack>
  11. #include <map>
  12. #include <iomanip>
  13. #define PI acos(-1.0)
  14. #define Max 2505
  15. #define inf 1<<28
  16. #define LL(x) ( x << 1 )
  17. #define RR(x) ( x << 1 | 1 )
  18. #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
  19. #define ll long long
  20. #define mem(a,b) memset(a,b,sizeof(a))
  21. #define mp(a,b) make_pair(a,b)
  22. #define PII pair<int,int>
  23. using namespace std;
  24.  
  25. bool flag[11111111] ;
  26. void prime(){
  27. flag[0] = 1 ;
  28. flag[1] = 1 ;
  29. flag[2] = 0 ;
  30. for (int i = 2 ;i <= 1300000 ; i ++ ){
  31. if(!flag[i]){
  32. for (int j = 2 * i ;j <= 1300000 ;j += i){
  33. flag[j] = 1 ;
  34. }
  35. }
  36. }
  37. }
  38. int a[111] ;
  39. int num[1111111] ;
  40. int main() {
  41. prime() ;
  42. int nn = 0 ;
  43. for (int i = 2 ;i <= 1300000 ;i ++ ){
  44. if(!flag[i])num[nn ++ ] = i ;
  45. }
  46. int n ;
  47. cin >> n ;
  48. cout << num[0] ;
  49. for (int i = 1 ;i < n ;i ++ ){
  50. printf(" %d",num[i]) ;
  51. }
  52. cout << endl;
  53. return 0 ;
  54. }

C,可以推出,k个连续的字符串是满足等比数列的关系的。

所以我们只需求出a1 和比例q就可以了。

首相就是只有一个字符串的时候,所有的删除的总和。

q就是pow(2 , l),l是字符串的长度。

等比数列求和公式 (a1 * (q ^ n - 1)) / (q - 1)%MOD 。先将a1 拿到外面去,不参与计算。我们设q ^ n - 1为a ,q - 1 为b 。那么式子就变成a / b %MOD 。这就变成很熟悉的拓展欧几里德了,先求出b % MOD的逆元x . x * b % MOD  = 1 ,那么 (a / b ) %MOD * (x * b) % MOD 的值不变,那么可以将式子化简成(a * x) % MOD 。

最后再将a1乘上即可。

  1. #define MOD 1000000007
  2.  
  3. char a[111111] ;
  4.  
  5. inline ll extend_gcd(ll a ,ll b , ll& x , ll& y){
  6. ll ans , t ;
  7. if(b == 0){
  8. x = 1 ;
  9. y = 0 ;
  10. return a ;
  11. }
  12. ans = extend_gcd(b , a % b ,x ,y ) ;
  13. t = x ;
  14. x = y ;
  15. y = t - (a / b) * y ;
  16. return ans ;
  17. }
  18.  
  19. ll quick_pow(ll a ,ll b , ll M){
  20. ll ret = 1 ;
  21. ll temp = a ;
  22. while(b){
  23. if(b & 1){
  24. ret = (ret * temp) % M ;
  25. }
  26. temp = (temp * temp) % M ;
  27. b >>= 1 ;
  28. }
  29. return ret ;
  30. }
  31. int main(){
  32. cin >> a ;
  33. int k ;
  34. cin >> k ;
  35. int l = strlen(a) ;
  36. ll a1 = 0 ;
  37. REP(i , 0 ,l - 1 ){
  38. if(a[i] == '0' || a[i] == '5'){
  39. a1 = (a1 + quick_pow(2 ,i ,MOD)) % MOD ;
  40. }
  41. }
  42. ll a = quick_pow(2 , l ,MOD) ;
  43. ll aa = (a - 1 + MOD) % MOD ;
  44. ll x , y ;
  45. extend_gcd(aa ,MOD , x ,y) ;
  46. x = (x + MOD) % MOD ;
  47. ll c = (quick_pow(a , k ,MOD) - 1) * x % MOD ;
  48. ll ans = c * a1 % MOD ;
  49. cout << ans << endl;
  50. return 0 ;
  51. }

D,DFS,每次进入一个空地,先将他建成蓝色的,然后向四个方向DFS,最后回溯的时候将这个蓝色的建筑拆掉建成红色的,当然第一个进入的点是不能建成红色的。

这个很容易证明,一个联通块里面,肯定有一个是蓝色的,其他都是红色的。

  1. int n , m ;
  2. char op[11111111] ;
  3. int xx[11111111] ;
  4. int yy[11111111] ;
  5. int ss[555][555] ;
  6. char Map[555][555] ;
  7. int num = 0 ;
  8. void dfs(int x ,int y ,int first ) {
  9. if(x < 1 || x > n || y < 1 || y > m)return ;
  10. op[num] = 'B' ;
  11. xx[num] = x ;
  12. yy[num] = y ;
  13. num ++ ;
  14. ss[x][y] = 0 ;
  15. if(ss[x - 1][y])dfs(x - 1 ,y , 1) ;
  16. if(ss[x][y - 1])dfs(x ,y - 1 ,1 ) ;
  17. if(ss[x + 1][y])dfs(x + 1 ,y , 1) ;
  18. if(ss[x][y + 1])dfs(x ,y + 1 ,1 ) ;
  19. if(first) {
  20. op[num] = 'D' ;
  21. xx[num] = x ;
  22. yy[num] = y ;
  23. num ++ ;
  24. op[num] = 'R' ;
  25. xx[num] = x ;
  26. yy[num] = y ;
  27. num ++ ;
  28. }
  29. }
  30. int main() {
  31. cin >> n >> m ;
  32. for (int i = 1 ; i <= n ; i ++ ) {
  33. for (int j = 1 ; j <= m ; j ++ ) {
  34. cin >> Map[i][j] ;
  35. if(Map[i][j] == '.') {
  36. ss[i][j] = 1 ;
  37. }
  38. }
  39. }
  40. for (int i = 1 ; i <= n ; i ++ ) {
  41. for (int j = 1 ; j <= m ; j ++ ) {
  42. if(ss[i][j]) {
  43. dfs(i ,j , 0 ) ;
  44. }
  45. }
  46. }
  47. cout << num << endl;
  48. for (int i = 0 ; i < num ; i ++ ) {
  49. cout << op[i] << " " << xx[i] << " " << yy[i] << endl;
  50. }
  51. return 0 ;
  52. }

E。状态压缩DP。

枚举1<< 24的状态。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <algorithm>
  4. #include <string>
  5. #include <cmath>
  6. #include <cstring>
  7. #include <queue>
  8. #include <set>
  9. #include <vector>
  10. #include <stack>
  11. #include <map>
  12. #include <iomanip>
  13. #define PI acos(-1.0)
  14. #define Max 2505
  15. #define inf 1<<28
  16. #define LL(x) ( x << 1 )
  17. #define RR(x) ( x << 1 | 1 )
  18. #define REP(i,s,t) for( int i = ( s ) ; i <= ( t ) ; ++ i )
  19. #define ll long long
  20. #define mem(a,b) memset(a,b,sizeof(a))
  21. #define mp(a,b) make_pair(a,b)
  22. #define PII pair<int,int>
  23. using namespace std;
  24.  
  25. #define MOD 1000000007
  26.  
  27. inline void RD(int &ret) {
  28. char c;
  29. do {
  30. c = getchar();
  31. } while(c < '0' || c > '9') ;
  32. ret = c - '0';
  33. while((c=getchar()) >= '0' && c <= '9')
  34. ret = ret * 10 + ( c - '0' );
  35. }
  36.  
  37. int a[111111] ;
  38. int sum[1 << 24] ;
  39. int dp[1 << 24] ;
  40. int k[11] ;
  41.  
  42. int main(){
  43.  
  44. int n ;
  45. cin >> n ;
  46. for (int i = 0 ;i < n ; i ++ ){
  47. RD(a[i]) ;
  48. }
  49.  
  50. int m ;
  51. cin >> m ;
  52. for (int i = 0 ;i < m ;i ++ ){
  53. RD(k[i]) ;
  54. }
  55. dp[0] = 1 ;
  56. for (int i = 1 ;i < (1 << n) ; ++ i){//枚举当前路径
  57. int pos ;
  58. bool flag = 0 ;
  59. sum[i] = 0 ;
  60. for (int j = 0 ;j < n ;j ++ ){
  61. if(i & (1 << j)){//i 在 j 这点为1 ,直接在这里找出sum[i]的值会T。O(2 ^ 24 * n)
  62. pos = j ;//一开始我直接写sum[i] += a[j] ;就T了
  63. break ;
  64. }
  65. }
  66. sum[i] = sum[i ^ (1 << pos)] + a[pos] ;//i 状态的所有步数。
  67. for (int j = 0 ; j < m ;j ++ ){//i状态的步数是否不能走。
  68. if(sum[i] == k[j]){
  69. dp[i] = 0 ;
  70. flag = 1 ;
  71. break ;
  72. }
  73. }
  74. if(flag)continue ;
  75. dp[i] = 0 ;
  76. for (int j = 0 ;j < n ;j ++ ){
  77. if(i & (1 << j)){//i 这位可以由i ^ (1 << j )这一状态过来。
  78. dp[i] = (dp[i] + dp[i ^ (1 << j)]) ;
  79. if(dp[i] >= MOD)dp[i] -= MOD ;
  80. }
  81. }
  82. }
  83.  
  84. cout << dp[(1 << n) - 1] << endl;
  85. return 0 ;
  86. }

CF 191 div2的更多相关文章

  1. cf 442 div2 F. Ann and Books(莫队算法)

    cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...

  2. CF#603 Div2

    差不多半年没打cf,还是一样的菜:不过也没什么,当时是激情,现在已是兴趣了,开心就好. A Sweet Problem 思维,公式推一下过了 B PIN Codes 队友字符串取余过了,结果今天早上一 ...

  3. CF R631 div2 1330 E Drazil Likes Heap

    LINK:Drazil Likes Heap 那天打CF的时候 开场A读不懂题 B码了30min才过(当时我怀疑B我写的过于繁琐了. C比B简单多了 随便yy了一个构造发现是对的.D也超级简单 dp了 ...

  4. CF#581 (div2)题解

    CF#581 题解 A BowWow and the Timetable 如果不是4幂次方直接看位数除以二向上取整,否则再减一 #include<iostream> #include< ...

  5. [CF#286 Div2 D]Mr. Kitayuta's Technology(结论题)

    题目:http://codeforces.com/contest/505/problem/D 题目大意:就是给你一个n个点的图,然后你要在图中加入尽量少的有向边,满足所有要求(x,y),即从x可以走到 ...

  6. CF 191 总结

    A. Flipping Game 链接:http://codeforces.com/contest/327/problem/A 题意:从 i 到 j 翻转一次使得 1 的 个数最多~ 直接暴力搞~ # ...

  7. CF 197 DIV2 Xenia and Bit Operations 线段树

    线段树!!1A 代码如下: #include<iostream> #include<cstdio> #define lson i<<1 #define rson i ...

  8. CF#345 div2 A\B\C题

    A题: 贪心水题,注意1,1这组数据,坑了不少人 #include <iostream> #include <cstring> using namespace std; int ...

  9. CF R303 div2 C. Woodcutters

    C. Woodcutters time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. 《Effective C++》Item2:尽量以const,enum,inline替换#define

    1. 宏定义 #define ASPECT_RATIO 1.653 该宏定义ASPECT_RATIO也许从来没有被编译器看到,也许在编译器开始处理源码之前就已经被预处理器替换了.所以记号名称ASPEC ...

  2. nginx install

    ./configure --prefix=/home/allen.mh/local/nginx --with-http_ssl_module --with-http_sub_module --with ...

  3. Cocos2dx游戏开发系列笔记13:一个横版拳击游戏Demo完结篇

    懒骨头(http://blog.csdn.net/iamlazybone QQ:124774397 ) 写下这些东西的同时 旁边放了两部电影 周星驰的<还魂夜> 甄子丹的<特殊身份& ...

  4. Html 小插件6 百度新闻插件

    新闻免费代码"http://news.baidu.com/newscode.html ,便可在输入希望订阅的关键词后,根据相关选项的设置,百度便非常快的在当前页面的文本编辑框内生成相关代码. ...

  5. rsyslogd: error during parsing file /etc/rsyslog.conf, on or before line 55: warnings occured in fil

    zjtest7-frontend:/root# rsyslogd -n rsyslogd: error during parsing file /etc/rsyslog.conf, on or bef ...

  6. HDU 5768 Lucky7(CRT+容斥原理)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5768 [题目大意] 求出一个区间内7的倍数中,对于每个ai取模不等于bi的数的个数. [题解] 首 ...

  7. CodeForces 235C Cyclical Quest(后缀自动机)

    [题目链接] http://codeforces.com/contest/235/problem/C [题目大意] 给出一个字符串,给出一些子串,问每个子串分别在母串中圆环匹配的次数,圆环匹配的意思是 ...

  8. POJ 3294 Life Forms(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=3294 [题目大意] 求出在至少在一半字符串中出现的最长子串. 如果有多个符合的答案,请按照字典序输出. [题解] 将所有的字符串通 ...

  9. 具体解释http 协议

    HTTP协议的主要特点可概括例如以下: 1.支持客户/server模式. 2.简单高速:客户向server请求服务时,仅仅需传送请求方法和路径.请求方法经常使用的有GET.HEAD.POST.每种方法 ...

  10. POJ 1556 The Doors(计算几何+最短路)

    这题就是,处理出没两个点.假设能够到达,就连一条边,推断可不能够到达,利用线段相交去推断就可以.最后求个最短路就可以 代码: #include <cstdio> #include < ...