The Minimum Number of Variables 我们定义dp[ i ][ mask ]表示是否存在 处理完前 i 个a, b中存者 a存在的状态是mask 的情况. 然后用sosdp处理出,状态为state的a, 能组成的数字, 然后转移就好啦. #include<bits/stdc++.h> #define LL long long #define LD long double #define ull unsigned long long #define fi first #…
题目大意: 有一组n个不相同的数字组成数串:a1,a2,a3-an. 1.一个数组b. 2.第一个操作我们将b0的值赋为a1.之后我们有n-1个操作,第k次操作我们将by=bi+bj(y,i,j可能相同). 3.每次操作结束后我们依次取出by.按顺序组成新串. 问操作结束后,我们获得的新串能否与a数串相同.如果可以输出数组b所需的最小长度.反之输出-1. 思路: 先介绍一个纯dfs的算法:每次依次枚举i,j,y,然而会T. 不过,可以发现,b中的数必定在a中出现过.因此,记忆化搜索,状态(s)中…
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit…
E. Another Sith Tournament 题目连接: http://www.codeforces.com/contest/678/problem/E Description The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who wil…
Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) \(\exist b_i\in\mathbb{Z}^+,\sum\limits_{i=1}^na_ik^{-b_i}=1\) 考虑充分性,倘若我们已经知道了 \(b_1,b_2,\dots,b_n\) 的值怎样构造合并的序列,考虑 \(B=\max\limits_{i=1}^nb_i\),这里有一个结论,…
题目传送门 https://codeforces.com/contest/1103/problem/D 题解 失去信仰的低水平选手的看题解的心路历程. 一开始看题目以为是选出一些数,每个数可以除掉一个不超过 \(k\) 的因数,使得被选出这些数的 \(\gcd\) 为 \(1\). 错的有点离谱.然后想了半天,想了一个奇怪的思路结果没有任何优化空间(因为选择的数不固定无法直接确定所有的质因子). 然后就开始看题解(事实上就算我没看错题目肯定也不会做). 以下为搬运题解内容. 我们可以先求出初始的…
题意:有n个菜,每个菜有个兴奋值,并且如果吃饭第i个菜立即吃第j个菜,那么兴奋值加ma[i][j],求吃m个菜的最大兴奋值,(n<=18) 分析:定义dp[status][last],status为每道菜的状态,1为吃,0为不吃,last为最后一个菜,dp[status][last],在status状态下最后吃last的最大兴奋值,然后枚举status去更新后面的状态,详细见代码 AC代码: #include <bits/stdc++.h> #define ll long long us…
题意:给你一个长度为n的序列 问你需要多少次两两交换 可以让相同的数字在一个区间段 思路:我们可以预处理一个数组cnt[i][j]表示把i放到j前面需要交换多少次 然后二进制枚举后 每次选择一个为1的位置 考虑这个位置最后加进来的花费取最小 #include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const double eps = 1e-6; const int N = 4e5+7; typedef…
题目链接: http://codeforces.com/problemset/problem/8/C C. Looking for Order time limit per test:4 secondsmemory limit per test:512 megabytes 问题描述 Girl Lena likes it when everything is in order, and looks for order everywhere. Once she was getting ready f…
http://codeforces.com/gym/100405 D题 题在pdf里 codeforces.com/gym/100405/attachments/download/2331/20132014-acmicpc-northwestern-european-regional-contest-nwerc-13-en.pdf D - Diagrams & TableauxA Young diagram is an arrangement of boxes in rows and colum…