题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> using namespace std; typedef long long ll; ; const int INF = 0x3f3f3f3f; ll dp[MAXN][]; ll cnt[MAXN]; ll work(…
打个表出来看看,其实很明显. 推荐打这俩组 11 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 10000000000 12 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 10000000000 100000000000 打出表来看出来,n为偶数时,每隔两行,对原序列的奇数项分配的权重形成二项展开式. n为奇数时,每隔四行,形成二…
题意:定义,对于a数组的一个子区间[l,r],f[l,r]定义为对该子区间执行f操作的值.显然,有f[l,r]=f[l,r-1] xor f[l+1,r].又定义ans[l,r]为满足l<=i<=j<=r的f[i,j]的最大值.多次询问你某些区间的ans值. ans=max(f[l,r],ans[l,r-1],ans[l+1,r]),直接递推即可. #include<cstdio> #include<algorithm> using namespace std;…
http://codeforces.com/contest/816/problem/E 题意: 去超市买东西,共有m块钱,每件商品有优惠卷可用,前提是xi商品的优惠券被用.问最多能买多少件商品? 思路: 第一件商品使用优惠券不需要前提,别的都是需要的,然后这样就形成了一棵以1为根的树. 这样,很容易想到是树形dp. d[u][j][0/1]表示以u为根的子数中选择j件商品所需的最少花费,0/1表示u商品是否能用优惠券. 解释一下代码中的sz[],它所代表的是以u为根的子树的结点数. 当我们现在访…
http://codeforces.com/contest/816/problem/B To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time r…
http://codeforces.com/contest/816/problem/A 题意: 给出一个时间,问最少过多少时间后是回文串. 思路: 模拟,先把小时的逆串计算出来: ① 如果逆串=分钟,那么此时已经是回文串了. ② 如果逆串>分钟,那么只需要逆串-分钟即可.(注意此时逆串>=60的情况) ③ 如果逆串<分钟,此时在这个小时内要构成回文串已经是不可能的了,那么就加上60-minute分钟,进入一个新的小时,然后重复上述步骤. #include<iostream>…
C. Karen and Game time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level,…
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the u…
容易发现,删除的顺序不影响答案. 所以可以随便删. 如果行数大于列数,就先删列:否则先删行. #include<cstdio> #include<algorithm> using namespace std; int p1,ans1[510*110],ans2[510*110],p2; int n,m,a[110][110]; int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;++i){ f…
C. Karen and Supermarket     On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars.…