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\),每次操作可以选择 ...
随机推荐
- Ajax监测开始执行及结束执行
特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...
- IView入门练习~CDN模式全局加载JS
关于 iView iView 是一套基于 Vue.js 的开源 UI 组件库,主要服务于 PC 界面的中后台产品. 特性 高质量.功能丰富 友好的 API ,自由灵活地使用空间 细致.漂亮的 UI 事 ...
- zabbix 监控hp 打印机
https://share.zabbix.com/search?searchword=hp+printer&search_cat=1
- 使用NSIS脚本制作一个安装包
大部分人第一次看到NSIS脚本都是一脸懵逼的.因为它这个脚本的结构乍一看上去就非常奇怪,不作说明的话是看不懂的. 编写脚本命令的时候要非常注意,命令要按照规定写在脚本中不同的段落里,也就是说,命令的先 ...
- python读取文件时遇到非法字符的处理 UnicodeDecodeError: 'gbk' codec can't decode bytes in position
报错UnicodeDecodeError: 'gbk' codec can't decode bytes in position ipath = 'D:/学习/语料库/SogouC.mini/Samp ...
- hdu 4511 (AC自动机)
注意标记一个点后,fail树上的子节点都会被标记 跑spfa,dp也可以 #include<iostream> #include<cstdio> #include<str ...
- keepalive + nginx 搭建高可用集群动态网站
环境准备: 两台节点部署keepalived,并且设为互为主从,实现高可用. 两台从节点部署nginx以及相关组件,作为真实服务器实现动态网站上线. 一.MASTER(BACKUP)节点下载keepa ...
- Apache web服务器(LAMP架构)
1.apache介绍 1).世界上使用率最高的网站服务器,最高时可达70%:官方网站:apache.org 2).http 超文本协议 HTML 超文本标记语言 3).URL 统一资源定位符 http ...
- itchat初步解读登录(转)
原文:https://blog.csdn.net/coder_pig/article/details/81357810 itchat的登录采取的是通过itchat.auto_login()这个函数来完 ...
- 数据结构系列之2-3-4树的插入、查找、删除和遍历完整版源代码实现与分析(dart语言实现)
本文属于原创,转载请注明来源. 在上一篇博文中,详细介绍了2-3树的操作(具体地址:https://www.cnblogs.com/outerspace/p/10861488.html),那么对于更多 ...