Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:有点意思的DP,学习状态表示方法的好题

Posted by ysp1205 at 2011-10-14 10:14:17 on Problem 3265
In Reply To:有点意思的DP,学习状态表示方法的好题 Posted by:applepi at 2010-10-09 22:05:55
> dp[当前月][月初余额] = 最大解决问题——错误的
> dp[已解决问题数][最后一次解决的问题数] = (消耗月份, 月初余额)——63MS
> dp[已解决问题数][月初余额] = 消耗月份——16MS
> 
> 第二个是咱的同学告诉咱的,没试过
> 看来状态表示的确是DP的一大课题啊……
。。。第一种可以啊 我用的就是第一种 ac了
#include <iostream>
#include <cstring>
using namespace std;
int m,p,d[350][1010],sx[1110],sy[1110];
int main()
{
      cin>>m>>p;
      for(int i=1;i<=p;i++)
      {
        cin>>sx[i]>>sy[i];
        sx[i]+=sx[i-1],sy[i]+=sy[i-1];
      }
      memset(d,-1,sizeof(d));
      d[1][0]=1;
      int ans=0;
      for(int i=1;i<=p+1&&ans==0;i++)
        for(int j=0;j<=m;j++)
      if(d[i][j]!=-1)
      {
          d[i+1][0]=max(d[i+1][0],d[i][j]); 
          if(d[i][j]==p+1){ans=i;break;} 
          int x1=d[i][j];
          for(int x2=x1;x2<=p;x2++)
          if(j+sx[x2]-sx[x1-1]>m||sy[x2]-sy[x1-1]>m)break;
          else
            d[i+1][sy[x2]-sy[x1-1]]=max(d[i+1][sy[x2]-sy[x1-1]],x2+1);
      }
      cout<<ans+1<<endl;
      //system("pause");
      return 0;
} 

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator