zoj1025 dp(呃。。)
2016-02-05 21:12
351 查看
这道题放在DP训练题组里,但是我用的贪心做出来的
题目大意:问最少能用多少组非递减数列覆盖所给数列。。网上看的大多数做法和我差不多,排序好以后进行搜索与标记,然后就AC了。。并不知道在哪里用DP。。
以下是代码:
题目大意:问最少能用多少组非递减数列覆盖所给数列。。网上看的大多数做法和我差不多,排序好以后进行搜索与标记,然后就AC了。。并不知道在哪里用DP。。
以下是代码:
#include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; struct anode { int len,weight; int ret; }a[12345]; bool cmp(anode x, anode y) { if(x.len==y.len) return x.weight<y.weight; return x.len<y.len; } int main() { // freopen("in.txt","r",stdin); int n,T; scanf("%d",&T); while(T--){ memset(a,0,sizeof(a)); scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&a[i].len,&a[i].weight); sort(a,a+n,cmp); int ans=0; for(int i=0;i<n;i++){ if(a[i].ret) continue; ans++; int tmp=a[i].weight; for(int j=i;j<n;j++){ if(a[j].weight>=tmp && a[j].ret==0) a[j].ret=1,tmp=a[j].weight; } } printf("%d\n",ans); } return 0; }
相关文章推荐
- 【Java】java使用反射访问对象方法和成员变量
- poj 1696 Space Ant(模拟+叉积)
- 数据结构实验之排序四:寻找大富翁
- nyoj 1237 最大岛屿(dfs)
- 单片机片内存储器烧写
- 第7讲项目3——发工资
- 使用DataGridView进行增删改查 并同步到数据库
- C语言 gets()和scanf()函数的区别
- [Leetcode]201. Bitwise AND of Numbers Range @python
- Java [Leetcode 223]Rectangle Area
- c++自制Redis数据库(三)初步基础框架设计
- 最简单的python命令解析器
- 数据结构实验之排序六:希尔排序
- 四大组件的工作过程
- Html表格<table>还是须要加入一些标签进行优化,能够加入标题<caption>和摘要<table summary>
- 118. Pascal's Triangle && 119. Pascal's Triangle II
- 数据结构实验之排序五:归并求逆序数
- glob模式
- 【jQuery基础学习】12 jQuery学习感想
- 第7讲项目2——三数最大值