随笔分类 - dp
摘要:``` #include #include #include #include using namespace std; const int N=3010; int e[N],h[N],ne[N],idx; int f[N][2]; bool st[N]; void add(int a,int b) { e[idx]=b; ne[idx]=h[a]; h[a]=idx++; } int n,m;
阅读全文
posted @ 2020-03-25 18:21
晴屿
摘要:``` #include #include #include #include #define int long long using namespace std; const int N=30000+10; const int mod=1000007; int a[N]; int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断
阅读全文
posted @ 2020-03-23 18:38
晴屿
摘要:``` #include #include #include #include using namespace std; const int N=300000+10; const int mod=1000007; //直接dp //dp[i]表示放了多少花 int dp[110]; int a[N]; int m,n; int main() { cin>>n>>m; for(int i=1;i>a
阅读全文
posted @ 2020-03-23 18:02
晴屿
摘要:``` #include #include #include #include using namespace std; const int N=300000+10; int dp[N]; int m,s,t; int main() { cin>>m>>s>>t; for(int i=1;i=10) dp[i]=dp[i-1]+60,m-=10; else dp[i]=dp[i-1],m+=4;
阅读全文
posted @ 2020-03-23 17:29
晴屿
摘要:``` #include #include #include #include using namespace std; const int N=1010; int a[N]; int sum; int main() { int t; cin>>t; while(t--) { int n; cin>>n; sum=0; int pos=0; for(int i=1;i>a[i]; sum+=a[i
阅读全文
posted @ 2020-03-21 21:04
晴屿
摘要:``` #include #include #include #include #include using namespace std; int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断正负 flag=1; else if(ch>='0'&&ch='0'&&ch0) f[u]+=f[v]; } } bool vis[N]
阅读全文
posted @ 2020-03-21 20:47
晴屿
摘要:``` #include #include #include #include using namespace std; const int N=2010; int a[N],f[N][N]; int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断正负 flag=1; else if(ch>='0'&&ch='0'&&ch<='
阅读全文
posted @ 2020-03-21 20:30
晴屿
摘要:``` //将含有N个元素的一个集合分成M个子集,使得每个子集的最大值与最小值平方差的和最小。 #include #include #include #include using namespace std; typedef long long ll; const int maxn = 1e4+50; const int maxm = 5e3+50; ll dp[maxn][maxm] ,v[ma
阅读全文
posted @ 2020-03-18 18:11
晴屿
摘要:参考博客https://blog.csdn.net/qq_26572969/article/details/47155559
阅读全文
posted @ 2020-03-18 18:02
晴屿
摘要:```#include#include#include#includeusing namespace std;const int N=1e5;int val[N],sum[N],dp[N];int q[N],r,l;int getup(int r,int l) { return dp[r]-dp[l];}int getdown(int r,int l) { return sum[r]-...
阅读全文
posted @ 2020-03-18 17:44
晴屿
摘要:``` #include #include #include #include using namespace std; typedef long long ll; const int N= 500000+10; int q[N],l,r; ll sum[N],val[N]; ll dp[N]; int n,m; ll getdown(int j,int k) { return val[j+1]-
阅读全文
posted @ 2020-03-18 17:40
晴屿
摘要:``` //考虑在V个村庄中只建立【一个】邮局的情况,显然可以知道, //将邮局建立在中间的那个村庄即可。也就是在a到b间建立一个邮局, //若使消耗最小,则应该将邮局建立在(a+b)/2这个村庄上 //下面考虑建立【多个】邮局的问题,可以这样将该问题拆分为若干子问题, //在前i个村庄中建立j个邮局的最短距离, //是在前【k】个村庄中建立【j-1】个邮局的最短距离 与 //在【k+1】到第i个
阅读全文
posted @ 2020-03-18 16:36
晴屿
摘要:``` #include #include #include #include using namespace std; typedef long long ll; const int N=4e5+50; int q[N],l,r; ll sum[N],val[N]; ll dp[N]; int n,m; ll getdown(int j,int k) { return val[j+1]-val[
阅读全文
posted @ 2020-03-18 16:10
晴屿
摘要:``` #include #include #include #include using namespace std; const int N=1e5+10; int sum[N],dp[N]; int q[N]; inline double calc(int j,int i) { return (double)(sum[i]-sum[j])/(i-j); } int main() { int
阅读全文
posted @ 2020-03-18 14:02
晴屿
摘要:debug半天,也没找出错误,就是卡fread快读有点恶心, 参考博客https://blog.csdn.net/zyszlb2003/article/details/94427222 #include<stdio.h> #include<iostream> #include<string.h> #
阅读全文
posted @ 2020-03-18 13:25
晴屿
摘要:```#include#include#include#includeusing namespace std;const int MAX = 1000+10;//dp[i][j]:把前 i 个数分成 j 段后能得到的序列的最小权值和//dp[i][j] = min( dp[k][j-1] + cost[i] - cost[k] - sum[k] *(sum[i] - sum[k]) ) ;//su...
阅读全文
posted @ 2020-03-17 20:35
晴屿
摘要:```#include#include#include#includeusing namespace std;typedef long long ll;const int N=5e5+10;int n,m,c;int q[N];ll dp[N];ll sum[N];ll get_y(int j,int k){ return dp[j]+sum[j]*sum[j]-dp[k]-sum[k]*sum[...
阅读全文
posted @ 2020-03-17 19:41
晴屿
摘要:```//f[i]表示所有将前i个任务处理完的方案,划分方案//属性为花费最小值//表示最后一批,枚举上一批,当上一批到1时,那么最后一批就是2到i//上一批到2时,那么最后一批就是3到i,上一批最多到i-1//上一批到j,那么最后一批就是j+1到i //前面的花费为f[j] //令执行时间前缀和为sumt,启动时间前缀和为sumc//那么最后一部分的花费为sumt[i]*(sumc[i]-sum...
阅读全文
posted @ 2020-03-17 16:32
晴屿