题目传送门 /* 贪心/二分查找:首先对ai%=p,然后sort,这样的话就有序能使用二分查找.贪心的思想是每次找到一个aj使得和为p-1(如果有的话) 当然有可能两个数和超过p,那么an的值最优,每次还要和an比较 注意:不能选取两个相同的数 反思:比赛时想到了%p和sort,lower_bound,但是还是没有想到这个贪心方法保证得出最大值,还是题目做的少啊:( */ #include <cstdio> #include <algorithm> #include <cst…
The link to problem:Problem - D - Codeforces   D. Range and Partition  time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Given an array a of n integers, find a range of values [x,y] (x≤y…
Luogu 3402 最长公共子序列(二分,最长递增子序列) Description 经过长时间的摸索和练习,DJL终于学会了怎么求LCS.Johann感觉DJL孺子可教,就给他布置了一个课后作业: 给定两个长度分别为n和m的序列,序列中的每个元素都是正整数.保证每个序列中的各个元素互不相同.求这两个序列的最长公共子序列的长度. DJL最讨厌重复劳动,所以不想做那些做过的题.于是他找你来帮他做作业. Input 第一行两个整数n和m,表示两个数列的长度. 第二行一行n个整数\[a_1,a_2,-…
#!/usr/bin/python # -*- coding: UTF-8 -*- worlds = ['fosh','fort','vista','fish','hish','hello','ohddad','abofa'] user_input = 'frt' def find_longest_substring(world_a,world_b): """ 查找最长公共子序列函数 """ # 根据字符串长度生成矩阵 matrix = [[0…
Bridging signals Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9234   Accepted: 5037 Description 'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up co…
问题描述: 给定两个序列X={x1,x2,…,xm}和Y={y1,y2,…,yn},找出X和Y的最长公共子序列.(给定两个序列X和Y,当另一序列Z既是X的子序列又是Y的子序列时,称Z是序列X和Y的公共子序列.) 细节须知(与之前随笔的对比): 将由数组存储起来一并输出至文件修改为边运行边输出,增加了程序的鲁棒性. 算法原理: a.最长公共子序列的结构 对X的所有子序列,检查它是否也是Y的子序列,从而确定它是否为X和Y的公共子序列.并且在检查过程中记录最长的公共子序列.X的所有子序列都检查过后即可…
题目描述 给出一个正整数x,问x最少能由多少个Fibonacci数加减算出. 例如1070=987+89-5-1,因此x=1070时答案是4. 输入 第一行一个正整数q (q<=10),表示有q组输出. 下面q行每行一个正整数x (x<=4*10^17). 输出 输出q行,依次表示每个输出的答案. 样例输入 1 1070 样例输出 4   因为f[i]=f[i-1]+f[i-2],f[i+1]=f[i]+f[i-1],能得到2f[i]=f[i+1]+f[i-2],所以最优答案一定存在没有一个F…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1065    Accepted Submission(s): 536 Problem Description Today, bes…
#include <iostream> #include <cstring> #define N 50010 using namespace std; int n; int num[N],dp[N],c[N]; int LIS(int *d){ memset(c,0,sizeof(c)); c[1]=d[1]; int l,r,mid,len=1; for(int i=2;i<=n;i++){ l=1; r=len; while(l<=r){ mid=(l+r)/2;…
LCIS                                                              Time Limit: 6000/2000 MS (Java/Others)                                                                 Memory Limit: 65536/32768 K (Java/Others)                                       …