Codeforces 934 最长不递减子序列 多项式系数推导
A
B
C
给你一个长度为N的01串 你可以翻转一次任意【L,R】的区间
问你最长的不递减序列为多少长
处理出1的前缀和 和2的后缀和
然后N^2 DP 处理出 【L,R】区间的最长不递增序列
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
const int MAXN = ;
int a[];
int pre[];
int suf[];
int dp[][][];
int ans = ;
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
cin >> a[i];
}
for (int i = ; i <= n; i++)
{
pre[i] = pre[i - ] + (a[i] == );
}
for (int i = n; i >= ; i--)
{
suf[i] = suf[i + ] + (a[i] == );
}
for (int i = ; i <= n; i++)
{
ans = max(pre[i] + suf[i], ans);
}
//cout<<ans<<endl;
for (int i = ; i <= n; i++)
{
for (int j = i; j <= n; j++)
{
dp[i][j][] = dp[i][j - ][] + (a[j] == );
dp[i][j][] = max(dp[i][j - ][], dp[i][j - ][]) + (a[j] == );
ans = max(ans, max(dp[i][j][], dp[i][j][]) + pre[i - ] + suf[j + ]);
}
}
cout << ans << endl;
}
D
找规律
考虑构造q(x).先让常数项小于k,也就是让相乘后的常数项+p小于k.
q(x)的常数项就是p / (-k).这样会产生一次项,那么继续消一次项.直到最后的p = 0.
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = ;
int cnt;
int ans[];
int main()
{
ll p;
ll k;
cin >> p >> k;
ll flag = ;
while (p != )
{
ans[++cnt] = p % k;
p = p / k * (-);
if (flag)
{
p += flag;
flag = ;
}
if (p < )
{
flag += (k - p) / k;
p += flag * k;;
}
}
cout << cnt << endl;
for (int i = ; i <= cnt; i++)
{
cout << ans[i] << " ";
}
cout << endl;
return ;
}
Codeforces 934 最长不递减子序列 多项式系数推导的更多相关文章
- Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列
D. Once Again... You a ...
- HDU 5532 Almost Sorted Array (最长非递减子序列)
题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...
- HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)
6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...
- python练习——最长的递减子序列
题目: 求一个数组的最长递减子序列比 , 如随机生成一组序列 {8,9,6,3,6,2,3,4} 求得最长递减序列 {9,8,6,4,3,2} list=[3,3,3,3,6,2,3,4] //冒 ...
- HDU 6357.Hills And Valleys-动态规划(区间翻转l,r找最长非递减子序列)
题意:给一串由n个数字组成的字符串,选择其中一个区间进行翻转,要求翻转后该字符串的最长非降子序列长度最长,输出这个最长非降子序列的长度以及翻转的区间的左右端点 #include<bits/std ...
- HDU 1025 Constructing Roads In JGShining's Kingdom[动态规划/nlogn求最长非递减子序列]
Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65 ...
- Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #323 (Div. 2) Once Again... CodeForces - 582B 最长非下降子序列【dp】(不明白)
B. Once Again... time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)
题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...
随机推荐
- 深入浅出mysql笔记---0、序
深入浅出mysql笔记---0.序 一.总结 一句话总结: 心得:买书之前建议先找找电子书,纸质书太难带了 1.开源作用? 开源对mysql的发展至关重要 2.mysql在2002年就全面支持了事务, ...
- 1443:【例题4】Addition Chains
1443:[例题4]Addition Chains 题解 注释在代码里 注意优化搜索顺序以及最优化剪枝 代码 #include<iostream> #include<cstdio&g ...
- 线对 Line pairs、LP(分辨率cy/mm)
线对 (Line pairs) 是胶片.镜头等电影摄影领域的专用名词. 每毫米线对一般指分辨率的单位,指仪器在一毫米内能分辨出多少对线. 在一定尺度内的可分辨线对数常被用来衡量仪器的空间分辨能力,能分 ...
- rocketMQ 通信协议格式
rocketMQ 使用 netty 通信,端对端的通信,为了避免粘包.分包,需要指定发送数据的边界. 使用的解码器是 LengthFieldBasedFrameDecoder // org.apach ...
- .NET中使用EF6与连接MYSQL
ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案,不仅支持SQL Server,还支持MySQL.Ora ...
- Intellij IDEA 常见问题
右击项目时,没有 Java Class,只能创建其他文件 IDEA 还没有将这个项目识别为 Maven 项目时,会出现这种情况.此时右键无法创建类. 解决办法: 手动为 IDEA 指定项目类型:如果编 ...
- 一文学会Go - 2 数据结构与算法实践篇
练习:使用go语言实现冒泡排序和归并排序 冒泡排序是所有排序算法中最简单的,练习时先实现它: func bubbleSort(array []int) { n := len(array) ; j &l ...
- windows 的cmd设置代理的问题
今天给公司一同事用cmd来安装gulp(npm install -g gulp), 死活安装不上,一直报一大堆的错误:经仔细查阅是代理的问题,故总结如下: 若公司的电脑是通过设置代理来访问外网,则需要 ...
- lua正则表达式替换字符串
local _t = {} _t.name = "Li" local str = string.gsub("hahah---[name]----[age]--xrz-&q ...
- ubuntu18.04 安装mongodb并使用Robo 3T连接Mongodb数据库
1.前提: 系统:ubuntu18.04 64位 数据库:mongodb GUI:Robo 3T 2018.3.0 描述: mongodb 安装在局域网内的ubuntu的机子上面, 在win 下 ...