hdu 3718 Different Division】的更多相关文章

Different Division Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 234    Accepted Submission(s): 90 Problem Description Now we will give you a graph, there are many points in the graph. We wil…
HDU 3718 Similarity 题目链接 题意:给定一个标准答案字符串,然后以下每一行给一个串.要求把字符一种相应一种,要求匹配尽量多 思路:显然的KM最大匹配问题,位置相应的字符连边权值+1 代码: #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const int MAXNODE = 27; typede…
http://acm.hdu.edu.cn/showproblem.php?pid=3480 题意:一个n个元素的集合S要求分成m个子集且子集并为S,要求$\sum_{S_i} (MAX-MIN)^2$最小.(n<=10000, m<=5000) #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <iostream>…
多校1 1004 HDU-6036 Division Game 题意 有k堆石头(0~k-1),每堆n个.\(n=\prod_{i=0}^{m}p_i^{e_i}\).\(0\le m,k \le 10,2\le p\le 10^9,1\le e_i,\sum_{i=0}^me_i\le 10^5,\) 现在第i次操作可以选择第i%k堆石头,移走该堆部分石头,使得剩下的数是原来的约数.当某堆不能操作时游戏结束.求结束于每一堆的方案数.答案取模\(985661441\). 题解 参考官方题解. 对…
一个二分图最大匹配的题: 匈牙利算法不熟: 建了个模,用最小费用最大流解决了 #include <iostream> #include <cstring> #define INF 9999999 #include <cstdio> #include <queue> #include <vector> #include<algorithm> using namespace std; #define maxn 6100 struct ed…
$dp$,字典树. $dp$递推式很容易知道.dp[i]=max{dp[j]+1} a[j]^..^a[i]<=X,并且$[j,i]$长度不能超过$L$. 但是暴力来复杂度极高,所以需要用字典树维护这个东西.将前缀异或和插入到字典树中,然后不断维护$a[i]$位置之前$L$个前缀异或和就好了. 跑了$405ms$,第一次排到第一,有点激动~~~ #pragma comment(linker, "/STACK:1024000000,1024000000") #include<…
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define MAXN 50 #define inf 65553566 int love[MAXN][MAXN]; /// 记录每个妹子和每个男生的好感度 int ex_girl[MAXN]; /// 每个妹子的期望值 int ex_boy[MAXN]; /// 每…
题目链接:hdu 3480 Division 题意: 给你一个有n个数的集合S,现在让你选出m个子集合,使这m个子集合并起来为S,并且每个集合的(max-min)2 之和要最小. 题解: 运用贪心的思想,肯定首先将全部的数排好序,然后设dp[i][j]表示前j个数分为i个集合的最优解. 则有dp[i][j]=min{dp[i-1][k]+(a[j]-a[k+1])2}(0<k<j). 这样写出来是三层for的dp,考虑用斜率优化降维. 假设l<k<j,对于dp[i][j],k到j为…
/* HDU 6036 - Division Game [ 组合数学,NTT ] | 2017 Multi-University Training Contest 1 题意: k堆石子围成一个圈,数量均为n,编号为0至k-1 第i轮可以操作第 (i+1) mod k 堆石子,必须拿石子且原石子数量要求整除操作后石子数量 任意一堆石子只剩一颗后停止游戏,问游戏停止在第i堆的方案数 限制: n很大,按唯一分解定理形式给出 n = p1^e1 * p2^e2 * ... * pm^em m,k <=…
HDU 6036 Division Game 考虑每堆石头最多操作 $ \sum e $ 次,考虑设 $ f(x) $ 表示某一堆石头(最开始都是一样的)操作 $ x $ 次后变成了 $ 1 $ 的方案数量. 明显的,某一堆石头操作了 $ x $ 次后仍然没有变成 $ 1 $ 的方案数量是 $ f(x+1) $.因为最后一次操作必然是把石头从某个数字拿到1.(这个算个小trick吧?) 那么对于第 \(k\) 堆石头答案就是 $ f^{k-1}(x+1) f^{m-i+1}(x) $ 因为前 $…
IMO, version 1 better than version 2, version 2 better than version 3. make some preprocess to make you code simple and efficient. Here divide the input by 2, so you don't have to do dividsion on each loop. version 1 is best thanks to http://www.cnbl…
Division Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 999999/400000 K (Java/Others) Total Submission(s): 3984    Accepted Submission(s): 1527 Problem Description Little D is really interested in the theorem of sets recently. There’s a pro…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3480 Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 999999/400000 K (Java/Others) Little D is really interested in the theorem of sets recently. There’s a problem that confused him a long time.   …
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3480 题目大意:将n个数字分成m段,每段价值为(该段最大值-该段最小值)^2,求最小的总价值. 解题思路:很单纯的斜率优化DP,得出状态转移方程:dp[i][j]=min{dp[k][j-1]+(a[i]-a[k+1])^2}(j-1<=k<i),然后斜率优化降到O(n^2)就好了. 注意:数据类型建议用int,不要用long long,后者乘法计算时间是前者的四倍,否则C++可能会超时. 代码:…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2615 题解:挺简单的暴力枚举,小小的分治主要是看没人写题解就稍微写一下 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; typedef long long ll; ll a[] , ans , sum[]; str…
题目大意:一个有n个数的集合,现在要求将他分成m+1个子集,对子集i设si表示该集合中最大数与最小数的差的平方.求所有si的和的最小值.n<=10000,m<=5000. 分析:最优解的m个集合肯定不会相交,也不会出现空集,而且每个子集的数必定是连续的. 所以可以将n个数先排序,在来进行dp求解. f[i][j]表示前j个数分成i个集合的最优解. 转移方程为:f[i][j]=min(f[i-1][k]+(num[j]-num[k+1])^2 设决策点k1<k2,若有k2比k1更优,则有:…
Problem Description Little D is really interested in the theorem of sets recently. There’s a problem that confused him a long time.  Let T be a set of integers. Let the MIN be the minimum integer in T and MAX be the maximum, then the cost of set T if…
BUPT2017 wintertraining(15) #7E 题意 把数组A划分为k个区间,每个区间不超过L长度,每一个区间异或和之和为S.现在求:S不超过X,区间个数的最大值. 且A是这样给你的:A[1], P, Q.A[i]=(A[i-1]*P+Q)%M.M为\(2^{28}\). 题解 容易想到dp, dp[i] :前 i 个数最多划分多少个区间.s[i]为前缀异或和. dp[i]=max(dp[j]+1),i-L<j<i,且s[j]^s[i]\(\le\) x. dp[n]就是答案.…
把n个数分成m段,每段的值为(MAX - MIN)2,求所能划分得到的最小值. 依然是先从小到大排个序,定义状态d(j, i)表示把前i个数划分成j段,所得到的最小值,则有状态转移方程: d(j, i) = min { d(j-1, k) + (ai - ak+1)2 | 0 ≤ k < i } 设 l < k < i,且由k转移得到的状态比由l转移得到的状态更优. 有不等式: 整理成斜率形式: 后面的就可以相当于套模板了,不过这里要用滚动数组优化一下空间. #include <i…
解题思路 第一步显然是将原数组排序嘛--然后分成一些不相交的子集,这样显然最小.重点是怎么分. 首先,我们写出一个最暴力的\(DP\): 我们令$F[ i ][ j ] $ 为到第\(i\)位,分成\(j\)组的代价,我们可以写出如下 $ DP$ for( LL i = 1; i <= N; ++i ) F[ i ][ 1 ] = sqr( A[ i ] - A[ 1 ] ); for( LL j = 2; j <= M; ++j ) for( LL i = j; i <= N; ++i…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
G - Happy 2004 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1452 Description Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to dete…
转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i…
Divide the Sequence 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5783 Description Alice has a sequence A, She wants to split A into as much as possible continuous subsequences, satisfying that for each subsequence, every its prefix sum is not smal…
Balloon Comes! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 26455    Accepted Submission(s): 10055 Problem Description The contest starts now! How excited it is to see balloons floating aroun…
Four Operations Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 22    Accepted Submission(s): 12 Problem Description Little Ruins is a studious boy, recently he learned the four operations!Now h…
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=5095 Problem Description SVM(Support Vector Machine)is an important classification tool, which has a wide range of applications in cluster analysis, community division and so on. SVM The kernel function…
题目链接: PKU:http://poj.org/problem?id=3654 ZJU:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2936 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=2723 Description The Tyrell corporation uses a state-of-the-art electronic document system th…
题目链接:hdu 2829 Lawrence 题意: 在一条直线型的铁路上,每个站点有各自的权重num[i],每一段铁路(边)的权重(题目上说是战略价值什么的好像)是能经过这条边的所有站点的乘积之和..然后给你m个炮弹,让你选择破坏掉m段铁路,使剩下的整条铁路的战略价值最小. 题解: 和hdu 3480 Division(斜率优化DP)这题相同,只是方程不同而已,改改就行了. #include<bits/stdc++.h> #define F(i,a,b) for(int i=a;i<=…