删数问题-注意贪心策略-不严格
来源:互联网 发布:上海知恩服饰有限公司 编辑:程序博客网 时间:2024/05/01 06:02
http://blog.csdn.net/cxllyg/article/details/8213312
给定n位整数q,去掉其中任意k<=n个数字后,剩下的数字按原次序排列组成一个新的正整数。对于给定的n位正整数a和正整数k,设计一个算法找出剩下数字组成的新数最小的删数方案。
比如,178543删除四个数字后,最小的新数是13。
贪心策略:最近下降点优先。
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- void delek(vector<int> &s, int k)
- {
- int n=s.size();
- if(k>=n)
- ;
- else
- {
- while(k>0)
- {
- for(vector<int>::iterator it=s.begin(); it<s.end()-1 && *(it)<*(it+1); it++) ;
- s.erase(it);
- k--;
- }
- }
- }
- void main()
- {
- vector<int> s;
- s.push_back(1);
- s.push_back(7);
- s.push_back(8);
- s.push_back(5);
- s.push_back(4);
- s.push_back(3);
- delek(s, 4);
- for(vector<int>::iterator it=s.begin(); it!=s.end(); it++)
- cout<<*it;
- cout<<endl;
- }
0 0
- 删数问题-注意贪心策略-不严格
- 【贪心】删数问题
- 【贪心】删数问题
- 贪心 删数问题
- 贪心,删数问题
- [贪心] 删数问题
- 删数问题 贪心
- [贪心]删数问题
- 贪心 -- 删数问题
- 【贪心】【RQNOJ】删数问题
- 贪心算法 - 删数问题
- 删数问题(贪心)
- 贪心算法-删数问题
- 删数问题(贪心)
- 贪心算法---删数问题
- 贪心算法,删数问题
- 继续贪心:删数问题
- 删数问题 贪心法
- 搭建聊天的界面、输入图片和文本
- java反射机制之基础
- 我和敏捷开发的故事--敏捷角色PO
- 利用json转变Python格式
- OpenGL GLSL
- 删数问题-注意贪心策略-不严格
- [Error]No enclosing instance of type XX is accessible. Must qualify the allocation with an e
- 暑假-二分图-D - Uncle Tom's Inherited Land
- 问题
- OC中如何进行多文件开发?
- iOS——创建Xcode 的Hello World
- 做葡萄酒全过程
- Linux/ubuntu 截图工具的使用
- 【leetcode每日一题】24.Swap Nodes in Pairs