当前位置: 首页 > news >正文

网站推广策划的策略官网模板建站塔山双喜

网站推广策划的策略,官网模板建站塔山双喜,网站建设公司的销售好做吗,网站建设大概价格E. 题意:n本书,每本书有颜色a[i],一次操作可以将其中一本书放在末尾,求满足:相同颜色的书都是相邻的 的最小操作次数. 显然最多只需要n次,考虑能节省多少次.倒着考虑,记f[i]为i~n最多能节约的次数.先预处理出每种颜色的出现的位置范围l[i],r[i]. 1.不节约这本书f[i] f[i 1]…E. 题意:n本书,每本书有颜色a[i],一次操作可以将其中一本书放在末尾,求满足:相同颜色的书都是相邻的 的最小操作次数. 显然最多只需要n次,考虑能节省多少次.倒着考虑,记f[i]为i~n最多能节约的次数.先预处理出每种颜色的出现的位置范围l[i],r[i]. 1.不节约这本书f[i] f[i 1] 2.if i l[a[i]], f[i] cnt[a[i]] f[r[a[i]]1] 3.if i ! l[a[i]], f[i] cnt[a[i]](位置i后的a[i]个数),为什么不加上f[r[a[i]]1]呢?首先这个转移必然不可能是最优的,肯定会被前面i l[a[i]]时替换掉,所以我们只考虑这部分被继承时的情况.如果被继承只有可能前面出现i l[a[i]],并且r[a[i]]i,那么f[i] cnt[a[i]] f[r[a[i]1]],此时我们保留a[i]和i以及i后面的a[i]不动,先将i前面i后面的a[i]移到末尾,再把其他与a[i],a[i]不同的数移到末尾即可. #include bits/stdc.h #define int long long #define IOS ios::sync_with_stdio(false), cin.tie(0) #define ll long long // #define double long double #define ull unsigned long long #define PII pairint, int #define PDI pairdouble, int #define PDD pairdouble, double #define debug(a) cout #a a endl #define point(n) cout fixed setprecision(n) #define all(x) (x).begin(), (x).end() #define mem(x, y) memset((x), (y), sizeof(x)) #define lbt(x) (x (-x)) #define SZ(x) ((x).size()) #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f // namespace nqio { const unsigned R 4e5, W 4e5; char* a, * b, i[R], o[W], * c o, * d o W, h[40], * p h, y; bool s; struct q { void r(char x) { x a b (b (a i) fread(i, 1, R, stdin), a b) ? -1 : *a; } void f() { fwrite(o, 1, c - o, stdout); c o; } ~q() { f(); }void w(char x) { *c x; if (c d) f(); } q operator (char x) { do r(x); while (x 32); return *this; } q operator (char* x) { do r(*x); while (*x 32); while (*x 32) r(*x); *x 0; return *this; } templatetypename t q operator(t x) { for (r(y), s 0; !isdigit(y); r(y)) s | y 45; if (s) for (x 0; isdigit(y); r(y)) x x * 10 - (y ^ 48); else for (x 0; isdigit(y); r(y)) x x * 10 (y ^ 48); return *this; } q operator (char x) { w(x); return *this; }q operator (char* x) { while (*x) w(*x); return *this; }q operator (const char* x) { while (*x) w(*x); return *this; }templatetypename t q operator (t x) { if (!x) w(48); else if (x 0) for (w(45); x; x / 10) *p 48 | -(x % 10); else for (; x; x / 10) *p 48 | x % 10; while (p ! h) w(*--p); return *this; } }qio; }using nqio::qio; using namespace std; mt19937 rnd(random_device{}()); const int N 2e6 10; int n, a[N], f[N], l[N], r[N]; mapint, int cnt; signed main() {IOS;cin n;for (int i 1; i n; i) {cin a[i];}for (int i 1; i n; i) {r[a[i]] i;}for (int i n; i 1; --i) {l[a[i]] i;}for (int i n; i 1; --i) {cnt[a[i]];f[i] f[i 1];if (i l[a[i]]) f[i] max(f[i], f[r[a[i]] 1] cnt[a[i]]);else f[i] max(f[i], cnt[a[i]]);}cout n - f[1] \n; } F. 题意:对n个节点1为根的树ab染色,有x个a,n-x个b.定义i节点上的字符串为1到i路径上的字符.求字符串种类数最少多少种,输出染色方案. 首先每一层尽可能染成一种颜色,如果恰好平分,那么答案为树的最大深度.这毫无疑问是答案下界,我们再去找答案上界,猜测是最大深度1.假设我们在染色某一层时,剩下m个点未染色,有t个非叶节点,那么我们肯定能将这t个非叶节点染成同一种颜色,因为至少还有t个叶子节点,我们只需要拿数量多的颜色来染即可,然后染叶子节点,显然能调整成与刚才非叶节点同一种颜色. 问题转化成了将每一层都染成a或者b,能否刚好染好每一层.这是一个典型的多重背包,我们将每层点的个数看成是物品,x或者n - x看成容积,然后求出选出若干层能否得到容积即可.由于要回溯,我们不压缩状态.设f[i][j]为考虑前i个物品,选的点数为j的可行性,可行性多重背包可以用贪心优化成O(nm).修改状态为f[i][j]为前i个物品凑出j的前提下,前i - 1个物品最多凑的价值. 这里详细说一下多重背包的优化方法: 由于我们只关注可行性,所以我们只需要关注会传递可行性的转移即可. 1.如果前i - 1个物品能凑出j,那么显然前i个也肯定能凑出来.if (f[i - 1][j] ! -1) f[i][j] j 2.如果前i - 1个物品凑不出来j,需要用第i个物品配合前i - 1个物品来凑,我们让体积从小到大枚举,先得到小于j能凑出来的体积,如果能凑出j - v[i],(v[i]为第i个物品的体积),那么如果还有至少一个i号物品,肯定能凑出j - v[i],换而言之,如果f[j - v[i]] ! -1 (j - f[i][j - v[i]) / v[i] cnt[i],那么f[i][j] f[i][j - v[i]]. 回溯的时候,我们需要求出拼成容积m每个价值的物品用了多少个.可以倒着来used[i] (cur - f[i][cur]) / v[i]; cur f[i][cur]. #include bits/stdc.h #define int long long #define IOS ios::sync_with_stdio(false), cin.tie(0) #define ll long long // #define double long double #define ull unsigned long long #define PII pairint, int #define PDI pairdouble, int #define PDD pairdouble, double #define debug(a) cout #a a endl #define point(n) cout fixed setprecision(n) #define all(x) (x).begin(), (x).end() #define mem(x, y) memset((x), (y), sizeof(x)) #define lbt(x) (x (-x)) #define SZ(x) ((x).size()) #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f // namespace nqio { const unsigned R 4e5, W 4e5; char* a, * b, i[R], o[W], * c o, * d o W, h[40], * p h, y; bool s; struct q { void r(char x) { x a b (b (a i) fread(i, 1, R, stdin), a b) ? -1 : *a; } void f() { fwrite(o, 1, c - o, stdout); c o; } ~q() { f(); }void w(char x) { *c x; if (c d) f(); } q operator (char x) { do r(x); while (x 32); return *this; } q operator (char* x) { do r(*x); while (*x 32); while (*x 32) r(*x); *x 0; return *this; } templatetypename t q operator(t x) { for (r(y), s 0; !isdigit(y); r(y)) s | y 45; if (s) for (x 0; isdigit(y); r(y)) x x * 10 - (y ^ 48); else for (x 0; isdigit(y); r(y)) x x * 10 (y ^ 48); return *this; } q operator (char x) { w(x); return *this; }q operator (char* x) { while (*x) w(*x); return *this; }q operator (const char* x) { while (*x) w(*x); return *this; }templatetypename t q operator (t x) { if (!x) w(48); else if (x 0) for (w(45); x; x / 10) *p 48 | -(x % 10); else for (; x; x / 10) *p 48 | x % 10; while (p ! h) w(*--p); return *this; } }qio; }using nqio::qio; using namespace std; mt19937 rnd(random_device{}()); const int N 2e6 10; int n, a[N], f[N], l[N], r[N]; mapint, int cnt; signed main() {IOS;cin n;for (int i 1; i n; i) {cin a[i];}for (int i 1; i n; i) {r[a[i]] i;}for (int i n; i 1; --i) {l[a[i]] i;}for (int i n; i 1; --i) {cnt[a[i]];f[i] f[i 1];if (i l[a[i]]) f[i] max(f[i], f[r[a[i]] 1] cnt[a[i]]);else f[i] max(f[i], cnt[a[i]]);}cout n - f[1] \n; }
http://www.w-s-a.com/news/992085/

相关文章:

  • 基础建设的网站有哪些内容成都科技网站建设咨询电话
  • 券多多是谁做的网站招聘网站开发模板
  • 网站主机一般选哪种的企业数字展厅
  • 网站建设该如何学衡水建设局网站首页
  • 高校网站建设工作总结番禺网站开发哪家好
  • 苏州 网站的公司wordpress主页代码
  • 怎么用html做图片展示网站外贸网站建设推广费用
  • 可以做本地生活服务的有哪些网站中油七建公司官网
  • 如何建设谷歌网站网站建设优点
  • 做网站的目标是什么产品宣传片制作公司
  • 柳州建设公司网站辽宁建设工程信息网评标专家入库
  • 合肥建设学校官方网站excel导入wordpress
  • 禹城网站设计做网站需要考虑哪些
  • 深圳做营销网站建设wordpress添加文章封面
  • 阿里云的网站建设方案织梦和wordpress哪个安全
  • 聊城网站建设公司电话wordpress怎么重新配置文件
  • 创业如何进行网站建设泰州公司注册
  • 免费网站建设培训学校手机百度高级搜索入口在哪里
  • 建站经验安徽六安发现一例新冠阳性检测者
  • 滨州内做网站系统的公司汕头网络营销公司
  • 苏州制作网站的公司哪家好wordpress google搜索
  • c语言做项目网站wordpress博客被书为什么还
  • 企业建站用什么系统网站建设补充协议模板
  • 常州网站关键字优化淘客网站怎么做排名
  • 全flash网站制作教程网站做进一步优化
  • 建设网站步骤是如何做自媒体和网站签约赚点击
  • 网站建设的闪光点网站 备案 拍照
  • 那些企业需要做网站九洲建设集团网站
  • 中山企业做网站昆明做网站价格
  • wordpress 新网站 代码网站可以做系统还原吗