题意及思路:https://www.cnblogs.com/Als123/p/11061147.html 代码: #include <bits/stdc++.h> #define LL long long #define INF 0x3f3f3f3f #define db double #define pii pair<int, int> using namespace std; const LL mod = 1e9 + 7; LL mul(LL x, LL y) { return…
题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类型,相同的物]品不一样的顺序代表不同,问有多少个序列 思路:首先范围是15个,这里我们可以用状压来代表选择哪些物品,然后这里是说不能有连续相同的类型,这里我们贪心考虑不全,最开始我考虑的是组合数的插空法,当时 发现有很多细节,写不了,这样的话我们就只能改成dp, 我们设置dp[i][j]   代表i…
因为不会打公式,随意就先将就一下? #include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<vector> using namespace std; typedef long long LL; ; ; int add (int x,int y) {x=x+y;return x>=MOD?x-MOD:x;} int mul (int…
Codeforces 1108E2 E2. Array and Segments (Hard version) Description: The only difference between easy and hard versions is a number of elements in the array. You are given an array \(a\) consisting of \(n\) integers. The value of the \(i\)-th element…
632E:http://codeforces.com/problemset/problem/632/E 参考:https://blog.csdn.net/qq_21057881/article/details/51023067 题意: 给定n个值,让你选择k个数,可以重复选择,问可以得到哪些数字. 思路: 显然最小的值起到很大的作用,我们可以把每个值都减去这个最小值,利用完全背包,建立dp[i]表示,取到 i 这么多值最少需要多少个数.如果取到 i值需要的数值小于等于K,那么k * 最小值 +…
题目描述: Playlist time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You have a playlist consisting of n songs. The -th song is characterized by two numbers *t**i* - its length and beauty respec…
Codeforces 题面传送门 & 洛谷题面传送门 智商掉线/ll 本来以为是个奇怪的反悔贪心,然后便一直往反悔贪心的方向想就没想出来,看了题解才发现是个 nb 结论题. Conclusion. 在最优方案中,至多只有一个数组只有部分被选,其余数组要么全选要么全都不选. 证明:考虑调整.假设存在两个数组 \(x,y\) 分别选了前 \(p,q\) 个元素,这里不妨假设 \(a_{x,p+1}\ge a_{y,q+1}\),那么考虑从 \(y\) 数组中拎 \(l=\min(len_x-p,q)…
给出一群女孩的重量和颜值 和她们的朋友关系 现在有一个舞台 ab是朋友 bc是朋友 ac就是朋友 给出最大承重 可以邀请这些女孩来玩 对于每一个朋友团体 全邀请or邀请一个or不邀请 问能邀请的女孩的最大颜值 比赛的时候一看就是个背包问题 似乎在背包九讲上面见过..但是不会写 于是百度.."背包 一类选一个" 百度出了分组背包 并且第一个搜索结果就是类似于原题的东西.. 只不过分组背包的模板是一个or不要 加了个bfs 把朋友团体作为一个新朋友加入进这个团体 改了改代码..就a了..…
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利用差分的思想,并且考虑到m比较小,遍历一遍序列,当前点遇到需要改变的时候进行操作,同时更新答案. #include <set> #include <map> #include <queue> #include <deque> #include <stack…
题目链接:Pictures with Kittens (hard version) 题意:给定n长度的数字序列ai,求从中选出x个满足任意k长度区间都至少有一个被选到的最大和. 题解:数据量5000,O(n^3)的DP不适用.需要加个单调队列优化. 注意每次是从$[i-k,i)$区间,选择加上ai.每次清空双向队列. #include <queue> #include <cstdio> #include <cstring> #include <iostream&g…