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\),每次操作可以选择 ...
随机推荐
- iOS AES-CBC、AES-ECB 加解密
简介 AES是加密的算法,使用128.192 和 256 位密钥,将被加密数据划分为128位(16字节)一块,然后使用某种加密模式进行加密 关键词: 块大小:16字节 密钥长度:AES算法下,key的 ...
- MYSQL,分别用一条语句交换两列的值与两行的值
测试表: CREATE TABLE `test` ( `id` ) NOT NULL AUTO_INCREMENT, `name` ) NOT NULL, ` DEFAULT CHARSET=utf8 ...
- 点云网格化算法---MPA
MPA网格化算法思路 第一步:初始化一个种子三角面.(随机选点,基于该点进行临近搜索到第二点:在基于该线段中点临近搜索到第三点) 图1 第二步:在种子三角面的基础上,进行面片的扩充,利用边的中点进行临 ...
- 【Python】—— 获取函数内部变量名称
原文出处: https://blog.csdn.net/maixiaochai/article/details/88693507 关键语句: func_vars = func.__code__.co_ ...
- Spoj375 Qtree--树链剖分
Spoj375 Qtree给一棵共有 n(n · 10000) 个结点的树, 每条边都有一个权值, 要求维护一个数据结构, 支持如下操作: 1. 修改某条边的权值; 2. 询问某两个结点之间的唯一通路 ...
- 【Qt开发】解决Qt5.7.0中文显示乱码的问题
[Qt开发]解决Qt5.7.0中文显示乱码的问题 亲测可用: 乱码主要是编码格式的问题,这里可以通过Edit菜单中选择当前文档的编码方式,选择按照UTF-8格式保存,然后输入对应的中文,保存,然后运行 ...
- 动态SQL之模糊查询
模糊查询学习了三种: DAO层 // 可以使用 List<User> wherelike01(String user_name); // 忘记 List<User> where ...
- SVN服务器和客户端使用教程总结
一.SVN简介 Subversion是什么? 它是一个自由/开源的版本控制系统,一组文件存放在中心版本库,记录每一次文件和目录的修改,Subversion允许把数据恢复到早期版本,或是检查数据修改的历 ...
- [19/06/06-星期四] HTML基础_文本标签、列表(有序、无序、定义)、文本格式化(单位、字体、大小写、文本修饰、间距、对齐文本)
一.文本标签 em:用来表示一段内容的着重点,语气上的强调.一般显示为斜体 i:是斜体显示,和em显示效果一样.h5规定不需要着重的内容而是单纯加粗或斜体可以用i或b.用的不多 strong:用来表示 ...
- 使用 Jenkins 打包成功后 运行 出现 Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
linux 运行时 错误日志 Error starting ApplicationContext. To display the conditions report re-run your appli ...