Tyvj p1209-minimum cut of intercepted missile plan & model conversion

Source: Internet
Author: User
P1209-intercept missiles from Admin Normal (OI)
Total time limit: 6 s memory limit: 128 MB code length limit: 64 kB background in background reality programmers alliance must start training from basic questions to cultivate skilled reserve talents. Description a missile interception system is developed to defend against missile attacks by the enemy. However, this missile interception system has a defect: although its first shell can reach any height, it cannot be higher than the previous one in the future. One day, the radar captured the enemy's missiles. Because the system is still in the test phase, there is only one system, so it may not be able to intercept all missiles. The input format is inputformat. There is only one line of input data. This row contains several data, which are separated by commas (,), indicating the height at which missiles fly in sequence (up to 20 missiles, the height is a positive integer not greater than 30000 ). The output format outputformat outputs only one row of data. This row contains two data, separated by commas. The first data indicates the maximum number of missiles that the system can intercept. The second data indicates the minimum number of such systems to intercept all missiles. Sample input sampleinput [Copy Data]
Sample output sampleoutput [Copy Data]
Pay attention to the data range and hint comments. do not submit the previous programs directly!
Source sourcenoip1999 classic problem provided by Sun reader [real programmer Alliance 2006.10]
The original question comes from tju. The most intuitive idea of the second question is the minimum cut. Each point is split to all the vertices that are above him, and can be further optimized, each vertex updates the vertex edge of the F value of the current vertex to the first question. If you think about it carefully, you will find that this is a plan. The minimum cut of the plan can be converted to the shortest path, we can find that the final minimal cut is actually the longest ascending subsequence.
#include<iostream>#include<cstring>#include<cstdio>using namespace std;#define MAXN 1000#define INF 0x3f3f3f3f//ACint num[MAXN];int f[MAXN];int main(){        freopen("input.txt","r",stdin);        int i,j,k,x,y,z,n,m;        n=1;        while (scanf("%d,",&num[++n])>0);        n--;        int ans=0;        num[0]=INF;        for (i=1;i<=n;i++)        {                for (j=0;j<i;j++)                {                        if (num[j]>=num[i])                                f[i]=max(f[i],f[j]+1);                        ans=max(ans,f[i]);                }        }        printf("%d,",ans);        memset(f,0,sizeof(f));        f[0]=0;        ans=0;        for (i=1;i<=n;i++)        {                for (j=0;j<i;j++)                {                        if (num[j]<num[i])                                f[i]=max(f[i],f[j]+1);                        ans=max(ans,f[i]);                }        }        printf("%d\n",ans-1);        return 0;}


Tyvj p1209-minimum cut of intercepted missile plan & model conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.