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 最长不递减子序列 多项式系数推导的更多相关文章

  1. Codeforces Round #323 (Div. 2) D. Once Again... 暴力+最长非递减子序列

                                                                                  D. Once Again... You a ...

  2. HDU 5532 Almost Sorted Array (最长非递减子序列)

    题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...

  3. HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)

    6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...

  4. python练习——最长的递减子序列

    题目: 求一个数组的最长递减子序列比 , 如随机生成一组序列 {8,9,6,3,6,2,3,4}   求得最长递减序列 {9,8,6,4,3,2} list=[3,3,3,3,6,2,3,4] //冒 ...

  5. HDU 6357.Hills And Valleys-动态规划(区间翻转l,r找最长非递减子序列)

    题意:给一串由n个数字组成的字符串,选择其中一个区间进行翻转,要求翻转后该字符串的最长非降子序列长度最长,输出这个最长非降子序列的长度以及翻转的区间的左右端点 #include<bits/std ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. Educational Codeforces Round 97 (Rated for Div. 2) E. Make It Increasing(最长非下降子序列)

    题目链接:https://codeforces.com/contest/1437/problem/E 题意 给出一个大小为 \(n\) 的数组 \(a\) 和一个下标数组 \(b\),每次操作可以选择 ...

随机推荐

  1. Mybatis 一对多 关联查询查询

    一对多 与 一对一 查询有许多相似之处. 最主要的区别是 查询结果是list,与之对应的标签为collection. 班级和学生,一个班有多个学生,而每个学生只能属于一个班. 此时班级编号作为学生表的 ...

  2. 移动端复制当前页面链接(URL)分享

    注释:在移动端想做一个复制当前URL类似于分享的功能 示例: <span class="share_btn"><img src="../resource ...

  3. js测试用

    一,大纲 二,目录二 三,目录三

  4. Python深度学习读书笔记-5.Keras 简介

    Keras 重要特性 相同的代码可以在 CPU 或 GPU 上无缝切换运行. 具有用户友好的 API,便于快速开发深度学习模型的原型. 内置支持卷积网络(用于计算机视觉).循环网络(用于序列处理)以及 ...

  5. MVC、MVP 和 MVVM

    MVC Model–View–Controller 模型:管理应用程序的数据.逻辑和规则 视图:展示数据(可以直接从模型中获取数据) 控制器:接收输入并将其转化成模型和视图的命令 MVP Model– ...

  6. 用JS实现快速排序

    "快速排序"的思想很简单,整个排序过程只需要三步: (1)在数据集之中,选择一个元素作为"基准"(pivot). (2)所有小于"基准"的元 ...

  7. python-接口开发flask模块(一)工具类准备

    我们常常听说测试http接口.测试java接口,测试socket接口等等:那么python这么强大的语言当然也可以用来开发接口了. flask模块介绍: python中用来开发接口的模块:flask, ...

  8. 【Struts2】工作流程

    转发两篇文章 一个请求在Struts2框架中的处理分为以下几个步骤: 1.客户端发出一个指向servlet容器的请求(tomcat): 2.这个请求会经过图中的几个过滤器,最后会到达FilterDis ...

  9. 【MM系列】SAP MM模块-查看移动平均价的历史记录

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-查看移动平均价的历 ...

  10. offsetof与container_of宏分析

    offsetof宏:结构体成员相对结构体的偏移位置 container_of:根据结构体成员的地址来获取结构体的地址 offsetof 宏 原型: #define offsetof(TYPE, MEM ...