Day1 Flying Birds

Source: Internet
Author: User

This is a typical dp,f[i][j],i of the horizontal axis, J for the ordinate, each horizontal axis with a complete backpack to calculate, some of the special, please understand in the program:

#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#defineMAXN 10010using namespacestd;Const intinf=0x7ffffff;intn,m,k,p,l,h;intX[MAXN],Y[MAXN],DOWN[MAXN],UP[MAXN];intf[maxn][1001];intMain () {Freopen ("bird.in","R", stdin); Freopen ("Bird.out","W", stdout); scanf ("%d%d%d",&n,&m,&k);  for(intI=0; i<n;i++) scanf ("%d%d",&x[i],&Y[i]);  for(intI=1; i<=n;i++) {Down[i]=0; Up[i]=m+1; }     for(intI=1; i<=k;i++) {cin>>p>>l>>h; DOWN[P]=M; UP[P]=h; }     for(intI=1; i<=n;i++)         for(intj=0; j<=m;j++) F[i][j]=inf; f[0][0]=inf; intArrive=K;  for(intI=1; i<=n;i++)     {         for(intj =1; J <= M; J + +)         {            if(J >= x[i-1]) {F[i][j]= Min (F[i][j], f[i-1][j-x[i-1]] +1); F[I][J]= Min (F[i][j], f[i][j-x[i-1]] +1); }            if(J = =m) { for(intk=j-x[i-1];k<=m;k++) {F[i][j]= Min (F[i][j], f[i-1][K] +1); F[I][J]= Min (F[i][j], f[i][k] +1); }            }        }         for(intj = down[i]+1; J <= up[i]-1; ++j)if(j + y[i-1] <=m) F[i][j]= Min (F[i][j], f[i-1][j+y[i-1]]);  for(intj =1; J <= Down[i]; J + +) F[i][j] =inf;  for(intj = Up[i]; J <= M; J + +) F[i][j] =inf; }    intcnt = k, ans =inf;  for(inti = n; I >=1; i--)     {         for(intj = down[i]+1; J <= up[i]-1; ++j)if(F[i][j] <inf) ans=min (ans, f[i][j]); if(ans = inf) Break; if(Up[i] <=m) CNT--; }    if(cnt==k) printf ("1\n%d\n", ans); Elseprintf ("0\n%d\n", CNT); return 0;}

Qing impartiality and is shot life pill is also ~

Day1 Flying Birds

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.