ZOJ - 1108 输出DP方案
DP方程太水不解释
熟悉一下输出的套路
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 1e4+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,dp[maxn],pre[maxn],aa,bb;
struct A{
int fat,speed,pos;
}a[maxn];
bool cmp(A a,A b){
return a.fat<b.fat;
}
int main(){
while(cin>>aa>>bb){
a[++n].fat=aa;
a[n].speed=bb;
a[n].pos=n;
}
sort(a+1,a+1+n,cmp);
rep(i,1,n) dp[i]=1;
rep(i,1,n){
rep(j,1,i-1){
if(a[i].fat>a[j].fat&&a[i].speed<a[j].speed){
if(dp[i]<dp[j]+1){
dp[i]=dp[j]+1;
pre[i]=j;
}
}
}
}
ll ans=1,st=1;
rrep(i,n,1) if(dp[i]>ans){
ans=dp[i];
st=i;
}
println(ans);
stack<int> stk;
while(st){
stk.push(st);
st=pre[st];
}
while(!stk.empty()){
println(a[stk.top()].pos);
stk.pop();
}
return 0;
}
ZOJ - 1108 输出DP方案的更多相关文章
- 背包DP 方案数
题目 1 P1832 A+B Problem(再升级) 题面描述 给定一个正整数n,求将其分解成若干个素数之和的方案总数. 题解 我们可以考虑背包DP实现 背包DP方案数板子题 f[ i ] = f[ ...
- ZOJ 1108 FatMouse's Speed (HDU 1160) DP
传送门: ZOJ:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=108 HDU :http://acm.hdu.edu.cn/s ...
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- zoj 1108 FatMouse's Speed 基础dp
FatMouse's Speed Time Limit: 2 Seconds Memory Limit:65536 KB Special Judge FatMouse believe ...
- ZOJ - 2402 DP方案数
题意:给出m,序列第i位是第i-1位的至少2倍大,的求长度为n且每一位范围均在1-m的序列方案数 对求方案数做不到信手拈来的感觉,需要加强 用简单的预处理和最优子结构能优化到很不错的效率了 #incl ...
- luogu P2066 机器分配[背包dp+方案输出]
题目背景 无 题目描述 总公司拥有高效设备M台,准备分给下属的N个分公司.各分公司若获得这些设备,可以为国家提供一定的盈利.问:如何分配这M台设备才能使国家得到的盈利最大?求出最大盈利值.其中M≤15 ...
- Codeforces 461B. Appleman and Tree[树形DP 方案数]
B. Appleman and Tree time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- ZOJ 3626(树形DP+背包+边cost)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3626 题目大意:树中取点.每过一条边有一定cost,且最后要回 ...
- CodeForces 27D - Ring Road 2 构图2-sat..并输出选择方案
题意 n个数1~n按顺序围成一个圈...现在在某些两点间加边..边可以加在圈内或者圈外..问是否会发生冲突?如果不发生冲突..输每一条边是放圈内还是圈外. 题解 ...
随机推荐
- Apache rotatelogs命令
一.简介 rotatelogs 是 Apache 自带的管道日志程序,可以完美的实现日志的轮转功能. 二.语法 Usage: rotatelogs [-v] [-l] [-L linkname] [- ...
- jQuery--后台主机列表编辑
先看效果: 要求: 全选,反选和取消 编辑模式下的全选,反选和取消 编辑模式下单选进入编辑状态,取消退出编辑状态 表格元素有可编辑,不可编辑,下拉选择 按住ctrl选择下拉框,下面的同列选项都随之改变 ...
- win32多线程 (一) 线程创建与结束等待
#include "stdafx.h"#include <Windows.h>#include <iostream> using namespace std ...
- hdu 4681 String(转载)
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream& ...
- (转)IIS处理并发请求时出现的问题及解决
原文地址:http://www.cnblogs.com/hgamezoom/p/3082538.html 一个ASP.NET项目在部署到生产环境时,当用户并发量达到200左右时,IIS出现了明显的请求 ...
- vmware10安装Arch
必须保证机器能够上网! 1.vmware10中创建虚拟机(跟虚拟机中安装其他系统同样的操作). 2.开启上一步中创建的虚拟机. 3选择第一项进入 4自动进入root命令行 5进入 /dev (进行分区 ...
- 在云主机后台进行python程序运行
nohup python main.py & nohup liunx自带的命令 注意:后面(&)!
- C#多线程编程实战1.7前台线程和后台线程
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- F题(水题)
给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. 例如: 1 7 6 3 1.i = 1, j = 3,对应的数为7 6 3,最大的数为7. ...
- winform datagridview某一列设为自动宽度
如果用displayedcells只会使看见的数据自动列宽,滚动条往下发现后面的没有自动列宽,所以要用allcells就不会出现这个问题