csu 1578: Opening Ceremony(DP)

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; 

int a[100005];
int dp[100005]; 

int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        sort(a+1,a+1+n);
        dp[0]=0;
        for(int i=1;i<=n;i++)
        {
            dp[i]=min(dp[i-1]+1,a[i]);
        }
        printf("%d\n",dp[n]);
    }
    return 0;
}

时间: 2024-10-05 17:07:47

csu 1578: Opening Ceremony(DP)的相关文章

csu 1578 Opening Ceremony (递推 )

题意:有一个排n个建筑 每个高不定 现在要消去全部建筑 方法有两种 1 消去高度为某值的全部方块 2 消去一整个建筑 问 如何通过最少步骤消去 思路:首先将数组从大到小排序 if(i+a[i]<ans) ans=i+a[i]; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int a[1000000+100]; int cmp(int a,int b) { r

Opening Ceremony

Problem E: Opening Ceremony Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 137  Solved: 30 [Submit][Status][Web Board] Description Input Output Sample Input 6 2 1 8 8 2 3 Sample Output 5 HINT 题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列.求要消去所有的砖块需要最小的操作数. 思

CodeForcesGym 100502E Opening Ceremony

Opening Ceremony Time Limit: 5000ms Memory Limit: 524288KB This problem will be judged on CodeForcesGym. Original ID: 100502E64-bit integer IO format: %I64d      Java class name: (Any) For the grand opening of the algorithmic games in NlogNsglow, a r

SOJ.Opening Ceremony

1003. Opening Ceremony     总提交数量: 123 通过数量: 34                 时间限制:1秒    内存限制:256兆 题目描述 For the grand opening of the algorithmic games in NlogNsglow, a row of tower blocks is set to be demolished in a grand demonstration of renewal. Originally the p

CSU 1547 Rectangle(dp、01背包)

题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1547 Description Now ,there are some rectangles. The area of these rectangles is 1* x or 2 * x ,and now you need find a big enough rectangle( 2 * m) so that you can put all rectangles into it(th

CSU 1120 病毒(DP)

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1120 解题报告:dp,用一个串去更新另一个串,递推方程是: if(b[i] > a[j]) m = max(m,dp[j]); else if(b[i] == a[j]) dp[j] = m + 1; 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<alg

CSU 1616: Heaps(区间DP)优化版

1616: Heaps Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 31  Solved: 5 [Submit][Status][Web Board] Description Zuosige always has bad luck. Recently, he is in hospital because of pneumonia. While he is taking his injection, he feels extremely bore

CSU 1527 Bounty Hunter dp 双调旅行商

题目链接:点击打开链接 裸的双调旅行商问题啦 #include <stdio.h> #include <string.h> #include <iostream> #include <math.h> #include <queue> #include <set> #include <algorithm> #include <stdlib.h> using namespace std; #define ll in

csu 1551(线段树+DP)

1551: Longest Increasing Subsequence Again Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: 267  Solved: 112[Submit][Status][Web Board] Description Give you a numeric sequence. If you can demolish arbitrary amount of numbers, what is the length of the