当前位置: 首页 > news >正文

网站建设预算计算方法建设营销网站

网站建设预算计算方法,建设营销网站,视频网站app怎么做的,济南市城市建设集团网站参考资料:《算法竞赛》,罗勇军 郭卫斌 著 本博客作为阅读本书的学习笔记,仅供交流学习。 建议关注 罗勇军老师博客 3. 单调队列与最大子序和问题 不限制子序列长度问题——贪心法或动态规划 HDOJ 1003 MAX SUM Max Sum Time Limit: 2000/10…

参考资料:《算法竞赛》,罗勇军 郭卫斌 著
本博客作为阅读本书的学习笔记,仅供交流学习。
建议关注 罗勇军老师博客

3. 单调队列与最大子序和问题

不限制子序列长度问题——贪心法或动态规划

HDOJ 1003 MAX SUM

Max Sum Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)

Problem Description
Given a sequence a[1],a[2],a[3]…a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.

Input

The first line of the input contains an integer T(1<=T<=20) which means the number of test cases. Then T lines follow, each line starts with a number N(1<=N<=100000), then N integers followed(all the integers are between -1000 and 1000).

Output
For each test case, you should output two lines. The first line is “Case #:”, # means the number of the test case. The second line contains three integers, the Max Sum in the sequence, the start position of the sub-sequence, the end position of the sub-sequence. If there are more than one result, output the first one. Output a blank line between two cases.

Sample Input
2
5 6 -1 5 4 -7
7 0 6 -1 1 -6 7 -5

Sample Output
Case 1: 14 1 4
Case 2: 7 1 6

Author
Ignatius.L

  1. 贪心法
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;int main() {int t; cin>>t;//测试用例个数for (int i = 1; i <= t; ++i) {int n; cin>>n;int maxsum = -INF;//最大子序和,初始设为一个最小的int负数int start = 1, end=1, p=1; //起点,终点,扫描位置int sum=0;for (int j = 1; j <= n; ++j) {int a; cin>>a; sum+=a;//读入一个元素,累加if (sum>maxsum){maxsum=sum;start=p;end=j;}if (sum<0){//扫描到j时,若前面的最大子序和是负数,从下一个重新开始求和sum=0;p=j+1;}}printf("Case %d:\n",i);printf(" %d %d %d\n",maxsum,start,end);if (i!=t) cout<<endl;}return 0;
}
  1. 动态规划
#include <bits/stdc++.h>
using namespace std;
int dp[100005];//dp[i]:以第i个数为结尾的最大值
int main(){int t; cin>>t;//测试用例个数for (int k = 1; k <= t; ++k) {int n; cin>>n;for (int i = 1; i <= n; ++i) cin>>dp[i];//用dp[]存储数据a[]int start=1, end=1, p=1;//起点,终点,扫描位置int maxsum = dp[1];for (int i = 2; i <= n; ++i) {if (dp[i-1]+dp[i]>=dp[i])//转移方程dp[i]=max(dp[i-1]+a[i],a[i])dp[i]=dp[i-1]+dp[i];//dp[i-1]+a[i]比a[i]大else p=i;//a[i]更大,则dp[i]=a[i]if (dp[i]>maxsum){//dp[i]更大maxsum=dp[i];start=p;end=i;//p开始,i结尾}}printf("Case %d:\n",k);printf(" %d %d %d\n",maxsum,start,end);if (k!=t) cout<<endl;}return 0;
}

限制子序列长度问题——单调队列

#include <bits/stdc++.h>
using namespace std;
deque<int> dq;
int s[100005];
int main(){int n,m;scanf("%d %d",&n,&m);for (int i = 1; i < n; ++i) scanf("%lld",&s[i]);for (int i = 1; i < n; ++i) s[i]=s[i-1]+s[i];//计算前缀和int ans = -1e8;dq.push_back(0);for (int i = 1; i <= n; ++i) {while(!dq.empty()&&dq.front()<i-m) dq.pop_front();//队头超过m范围:删头if (dq.empty()) ans = max(ans,s[i]);else ans= max(ans,s[i]-s[dq.front()]);//队头就是最小的s[k]while(!dq.empty()&&s[dq.back()]>=s[i]) dq.pop_back();//队尾大于s[i]:去尾dq.push_back(i);}printf("%d\n",ans);return 0;
}
http://www.hkea.cn/news/778293/

相关文章:

  • 如何在相关网站免费做宣传广告免费建立个人网站官网
  • 做搜狗网站优化首自己建立网站步骤
  • 企业资质查询官方网站最好的小说网站排名
  • 乐平网站设计北京互联网公司
  • 朝阳企业网站建设方案费用郑州网络营销学校
  • 建站行业发展百度广告代运营
  • 如何做积分商城网站鸡西seo顾问
  • p2p网站开发文档免费b站软件下载
  • 有没有做q版头像的网站今天百度数据
  • wordpress页面修改插件seo顾问阿亮
  • 政府门户网站建设标准国际婚恋网站排名
  • 上海青浦网站建设郑州靠谱seo电话
  • 网站建设怎么样seo专家招聘
  • 在网盘上怎么做自己的网站整站优化推广
  • php建设网站实训百度搜索引擎的总结
  • 怎么在360自己做网站重庆seo排名收费
  • 外贸网站建设浩森宇特教育培训报名
  • 网站开发价目表深圳市前十的互联网推广公司
  • php做视频直播网站关键词竞价广告
  • 重庆怎么站seo深圳网络推广团队
  • 自学软件网站开发网络推广怎样做
  • 最新版的wordpress怎么添加特征图优化关键词的作用
  • 深圳做网站google推广网络营销和传统营销的区别和联系
  • 专业做网站的顺德公司网络推广怎么收费
  • php商城网站建设多少钱天津百度seo排名优化
  • 注册网站免费注册insseo关键词优化推广哪家好
  • 深圳房地产网站开发常见的网络营销工具有哪些
  • .net 网站管理系统湖南企业竞价优化首选
  • 南山区住房与建设局官方网站网络赚钱推广
  • wordpress mycred汉化seo引擎搜索入口