C. Two Arrays

题目大意:就是给定两个整数n和m。计算数组对的数量(a,b),使得:

1 .两个阵列的长度都等于m;

2 .每个数组的每个元素都是1到n(包括1和n)之间的整数; 从1到m的任何指数I的ai≤bi; 数组a按非降序排序;

3 .数组b按非升序排序。

4.由于结果可能非常大,您应该以109+7为模来打印它。

思路:因为a对应位置的数都小于并且a单调递递增b单调递减那么b的最小值就大于a的最小值将a和b序列接起来就是一个长度为2m的上升子序列求方案数

dp[i][j] 就是以长度为i结尾数是j的方案数

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<unordered_map>
#include<bitset>
#include<cmath>
#define f first
#define s second
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;typedef  long long LL;
typedef pair<int,int> PII;
const int mod = 1e9 + 7;
const int N = 1e5 + 100;PII p[N];
LL h[N],n,m,T,s;
LL dp[30][1010];
int main()
{IOS;cin >> n >> m;m <<= 1;for(int i = 1; i <= n; ++ i)dp[1][i] = 1;for(int  i = 2; i <= m; ++ i)for(int j = 1; j <= n; ++ j)for(int k = 1; k <= j; ++ k)dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod;LL sum = 0;  for(int i = 1; i <= n; ++ i)sum = (sum + dp[m][i]) % mod;cout << sum;    return 0;
}

D. Minimax Problem

题目大意:就是给你n个长度为m的数组,挑出两个数组每个对应位置取最大,拼成一个新的长度为m的数组,始得b数组的最小值最大。

思路:通过观察数据范围,n <= 3 * 10^5 m <= 10;那么我们的算法复杂度只能是O(nlogn),并且答案不易求那么我们可以二分答案,判断答案是否存在,然后怎么写check函数呢

对于check函数我们可以状态压缩,枚举一行,将该行大于mid的数变成1,对于不同行我们记录一下状态,t vis[t] = i(行)

枚举一下状态就好了

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<unordered_map>
#include<bitset>
#include<cmath>
#define f first
#define s second
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
using namespace std;typedef  long long LL;
typedef pair<int,int> PII;const int mod = 1e9 + 7;
const int N = 3e5 + 100;
bitset<10> f;
int a[N][10];
int n, m, ansi, ansj;
int vis[N];
bool check(int mid)
{memset(vis,0,sizeof(vis));for(int i = 1; i <= n; ++ i){f.reset();for(int j = 1; j <= m; ++ j)if(a[i][j] >= mid)f |= 1 << (j - 1);vis[f.to_ulong()] = i;}for(int i = 0; i < (1 << m); ++ i)if(vis[i])for(int j = 0; j < (1 << m); ++ j)if(vis[j])if((i | j) == (1 << m) - 1){ansi = vis[i];ansj = vis[j];return true;}return false;
}int main()
{IOS;cin >> n >> m;for(int i = 1; i <= n; ++ i)for(int j = 1; j <= m; ++ j)cin >> a[i][j];int l = 0, r = INF;while(l <= r){int mid = (l + r) >> 1;if(check(mid)) l = mid + 1;else r = mid - 1;}cout << ansi << " " << ansj << endl;return 0;
}

E. Messenger Simulator

题目大意:给你长度为n 的 1~n的序列,进行m操作,每次操作将某一位的数放到第一位,其他位往后移动一位,问对于1 ~ n这个数输出它们最左的位置以及最右的位置

这就是样例模拟的过程
[1,2,3,4,5]
[3,1,2,4,5]
[5,3,1,2,4]
[1,5,3,2,4]
[4,1,5,3,2]

对于每一个数我们都要存储一个最左和最右,位置怎么表示呢? 对于一个数的位置表示位前面数的个数 + 1,就类似于前缀和,那么我们就可以用树状数组来维护,

在维护之前我们可以在每个数前面插入m个0,因为你移动到第一位再将数都后移显然太复杂了,我们直接,前面空出m个位置

比如说n = 3, m = 2;

0 0 1 2 3, 将2移动到前面就是0 2 1 0 3

将2填再m这个位置,再把2删掉

再移动3就是3 2 1 0 0;(因为0对前缀和没有影响)

下面看代码

#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cstring>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<unordered_map>
#include<bitset>
#include<cmath>
#define f first
#define s second
#define IOS std::ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INF 0x3f3f3f3f
using namespace std;typedef  long long LL;
typedef pair<int,int> PII;const int mod = 1e9 + 7;
const int N = 6e5 + 100;int tree[N];
int n, m, c;
int l[N], r[N];
int pos[N];
inline int lowbit(int x)
{return x & (-x);
}
inline void add(int x,int v)
{while(x <= N){tree[x] += v;x += lowbit(x);}
}inline int sum(int i)
{int res = 0;while(i){res += tree[i];i -= lowbit(i);}return res;
}int main()
{IOS;cin >> n >> m;for(int i = 1; i <= n; ++ i){ l[i] = r[i] = i; pos[i] = i + m;add(i + m,1);}int last = m;while(m -- ){cin >> c;l[c] = 1;int ans = sum(pos[c]);r[c] = max(r[c],ans);if(ans == 1) continue;add(pos[c],-1);add(last,1);pos[c] = last;last --;}for(int i = 1; i <= n; ++ i)r[i] = max(r[i],sum(pos[i]));for(int i = 1; i <= n; ++ i)cout << l[i] << " " << r[i] << endl;return 0;
}

Educational Codeforces Round 80 (Rated for Div. 2)SZU cf集训round2 C~E(dp,状压+二分,树状数组+逆向思维)相关推荐

  1. Educational Codeforces Round 80 (Rated for Div. 2) E. Messenger Simulator 思维 + 树状数组

    传送门 文章目录 题意: 思路: 题意: 给你nnn个人,一开始位置分别为1,2,...,n1,2,...,n1,2,...,n,让后mmm个操作,每次都将某个人移动到最前面,其他人依次顺延,求每个人 ...

  2. Educational Codeforces Round 80 (Rated for Div. 2) 二分 + 状压

    传送门 文章目录 题意: 思路: 题意: 给你nnn个长度为mmm的数组,选出两个来,让他们每一位取maxmaxmax构成新数组bbb,让后最大化bbb的最小值. 思路: 看到m=8m=8m=8,也就 ...

  3. Educational Codeforces Round 80 (Rated for Div. 2) C. Two Arrays 组合数|dp

    传送门 文章目录 题意: 思路: 题意: 给你n,mn,mn,m,让你构造两个数组a,ba,ba,b满足:1<=ai,bi<=n1<=a_i,b_i<=n1<=ai​,b ...

  4. Educational Codeforces Round 69 (Rated for Div. 2) D. Yet Another Subarray Problem(dp 最大子区间)

    D. Yet Another Subarray Problem time limit per test 2 seconds memory limit per test 256 megabytes in ...

  5. Educational Codeforces Round 108 (Rated for Div. 2) D. Maximum Sum of Products 思维 + dp

    传送门 文章目录 题意: 思路: 题意: 给你两个长度为nnn的数组a,ba,ba,b,你可以至多反转一段连续区间,求∑i=1nai∗bi\sum _{i=1}^n a_i*b_i∑i=1n​ai​∗ ...

  6. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  7. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  8. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  9. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

最新文章

  1. LoadRunner Controller集合点策略灰色问题 解决
  2. 自定义应用Crash时系统显示的对话框
  3. c# 用空格分割字符串_C#| 左用空格填充字符串
  4. phpcmsV9 自定义分页函数与调用 - 不影响后台SQL分页
  5. ubuntu 内Grub2配置详解(转)
  6. 卸载vuecli3_112、vue-cli3安装遇到的问题,卸载不掉旧版本,导致更新不了
  7. [导入]ATA 50 pin to 40 pin
  8. Vue组件创建和组件传值
  9. 项目微管理23 - 会议
  10. LigerUI权限系统之角色管理
  11. 带后台管理的超酷jquery+ajax幻灯相册php源码,js幻灯片轮播代码_js源码_js鼠标滚动翻页...
  12. web工时记录管理工具开发(一)
  13. 【状压DP】易懂讲解状态压缩/状态压缩DP
  14. 干货分享!手机中不可或缺的5个APP神器
  15. VMware的网络连接原理
  16. 怎么在linux系统中输入日历,Linux命令行上如何使用日历详解
  17. 2.Button按钮实例:普通按钮和图片按钮
  18. 【Java加解密系列】- SM2生成密钥
  19. Typora自定义样式--你值得拥有自己的styles
  20. 对拉格朗日乘数法和KKT条件的简单理解(来自PRML的附录)

热门文章

  1. 国内外有哪些漏洞信息发布平台?
  2. Java基本数据类型转换|字符和字符串
  3. JSP网页开发安装2019-03 eclipse,详细并且简单教程这里有。
  4. 必看干货|成为大数据专业人员必要且重要的7大技能
  5. 过年也学(nei)习 (juan)| 图像特征提取与匹配技术
  6. 每日一题(进制转换)
  7. 【T07】不要低估tcp的性能
  8. 修改tomcat6.0.25日志默认路径
  9. haproxy 反向代理 tomcat (https、负载均衡)
  10. 将SQL for xml path('')中转义的字符正常显示