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. 《Effective Java》读书笔记 - 6.枚举和注解

    Chapter 6 Enums and Annotations Item 30: Use enums instead of int constants Enum类型无非也是个普通的class,所以你可 ...

  2. 网络协议之FTP协议

    FTP(File Transfer Protocol) 协议文档:RFC 959 1.1 FTP协议介绍 FTP协议基于TCP/IP协议实现,处于应用层. FTP协议为C/S架构,每一次FTP连接,命 ...

  3. maven之阿里云Maven镜像的使用

    Maven中央仓库在国外,速度比较慢,所以我们采用国内的镜像,速度回有质的提升. 配置下setting.xml <mirrors> <mirror> <id>ali ...

  4. spring boot 整合saml2

    项目是国外的一位大神发布到githut上,这里只是对项目代码的分析与学习,也算是一种强化记忆 附上 githut地址:https://github.com/OpenConext/Mujina 项目分为 ...

  5. Linux_PXE服务器_RHEL7

    目录 目录 前言 PXE原理 搭建PXE服务器 关闭SELinux和防火墙 配置DHCP 配置TFTP 配置FTP 配置Kickstart 前言 PXE(preboot execute environ ...

  6. Jmeter接口测试系列之保存断言结果到文件

    在执行完接口测试用例后,我们需要将失败的用例结果统一保存到文件中,可以使用“断言结果”组件,并定制输出内容. 1.配置断言结果组件输出 (1.在文件名中配置需要保存的文件路径和文件名: (2.勾选仅日 ...

  7. Java程序员面试题集(151-180)

    Java面试题集(151-180) 摘要:这部分包含了Spring.Spring MVC以及Spring和其他框架整合以及测试相关的内容,除此之外还包含了大型网站技术架构相关面试内容. 151. Sp ...

  8. C# Hook 方法

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  9. 打印一个浮点数组,会输出字符串"Hello, world“ & 浮点数的二进制表示(IEEE 754标准)

    #include <stdio.h> #include<stdlib.h> int main() { float a[3] = { 1143139122437582505939 ...

  10. Django 实现分库

    网站后端的数据库随着业务的不断扩大,用户的累积,数据库的压力会逐渐增大.一种办法是优化使用方法,也就是的优化 SQL 语句啦,添加缓存以达到减少存取的目的:另外一种办法是修改使用架构,在数据库层面上「 ...