F - Select Half dp】的更多相关文章

LINK:Select Half 考试的时候调了一个小时给调自闭了 原来是dp的姿势不太对. 首先 容易发现 奇数最多空2个位置 偶数最多空1一个位置 然后 设f[i][j][k]表示第i个数选了没有j 且当前用了k个空位的最大值. 然后把自己给dp迷了 最后发现选的数量无法固定所以 这个dp崩了. 考虑贪心不难发现偶数最多有两个空位连在一起 这个可以暴力枚举 奇偶性直接拿. 奇数 可以三个空位连在一起 或者 有4个不相邻的空位 存在. 前者可以暴力枚举 后者需要一些诡异的操作 最后发现前后缀和…
题目大意:从n个数里边选n/2个数,问和最大是多少. 题解:这是一个比较有意思的DP,定义状态dp[i][1],表示选了第i个数的最优状态,dp[i][0]表示没有选第i个数的最优状态. 状态是如何转移的呢? 1  2  3  4  5  6  7.... 假设考虑到第7个数,前7个数我们要选7/2=3个数. 如果我们选了第7个数那么我们 只需要从前边再选2个数,我们可以从前5个数里边选2个,也可以从前4个数里边选2个,所以dp[i][1]=max({dp[i-2][1],dp[i-2][0],…
https://codeforces.com/contest/1132/problem/F 思维 + 区间dp 题意 给一个长度为n的字符串(<=500),每次选择消去字符,连续相同的字符可以同时消去,问最少需要消去多少次 题解 定义dp[l][r]为区间[l,r]剩下一个字符所需要的最小次数 dp[l][r]=min(dp[l][i]+dp[i+1][r]+x) x为消去剩下两个字符所需要的次数,假如两个字符相同需要x=-1 代码 #include<bits/stdc++.h> #de…
/** 题目:F. String Compression 链接:http://codeforces.com/problemset/problem/825/F 题意:压缩字符串后求最小长度. 思路: dp[i]表示前i个字符需要的最小次数. dp[i] = min(dp[j]+w(j+1,i)); (0<=j<i); [j+1,i]如果存在循环节(自身不算),那么取最小的循环节x.w = digit((i-j)/x)+x; 否则w = i-j+1; 求一个区间最小循环节: 证明:http://w…
思路: 每次枚举数字和也就是取模的f(x),这样方便计算. 其他就是基本的数位Dp了. 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #define ll __int64 #define pi acos(-1…
Problem Description Here is a function f(x): int f ( int x ) { if ( x == 0 ) return 0; return f ( x / 10 ) + x % 10; } Now, you want to know, in a given interval [A, B] (1 <= A <= B <= 10 9), how many integer x that mod f(x) equal to 0.   Input T…
Problem F "Folding" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description Bill is trying to compactly represent sequences of capital alphabetic characters from 'A' to 'Z' by folding repeating subsequences insid…
题意 给定一棵以 \(1\) 号点为根的树.若满足以下条件,则认为节点 \(p\) 处有一个 \(k\) 叉高度为 \(m\) 的堆: 若 \(m = 1\) ,则 \(p\) 本身就是一个 \(k\) 叉高度为 \(1\) 的堆. 若 \(m > 1\) ,则 \(p\) 需要有至少 \(k\) 个儿子满足在儿子处有一个 \(k\) 叉高度为 \(m − 1\) 的堆. 令 \(dp[p][k]\) 表示在 \(p\) 点 \(k\) 叉堆的最大高度,令 \(g[p][k]\) 为 \(p\)…
Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x) = An * 2n-1 + An-1 * 2n-2 + ... + A2 * 2 + A1 * 1. Now you are given two numbers A and B, please calculate how many numbers are there between…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 Time Limit: 1000/500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description For a decimal number x with n digits (AnAn-1An-2 ... A2A1), we define its weight as F(x) = An * 2n…