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

谢谢你,能讲讲我错在哪了么,始终想不通为什么WA,WA了20+次

Posted by sunmoonstar_love at 2005-07-11 00:33:11 on Problem 2465
In Reply To:方程是对的,我用下面的代码AC了 Posted by:xfxyjwf at 2005-07-11 00:16:02
> //用~划出了增加的代码
> //#include <stdio.h>
> #include<iostream>
> //#include<fstream>
> using namespace std;
> int f[102][201],i,j,k,d,dis[102],sta[102],pri[102],n,inf = 1000000000,tmp;
> 
> int main()
> {
>  //   freopen("in.txt","r",stdin);
>  //   freopen("out2.txt","w",stdout);
> //    scanf("%d",&d);
> //    ifstream cin("in.txt");
> //    ofstream cout("out2.txt");
>     cin>>d;
>     n = 1;
>     while(cin>>sta[n]>>pri[n] && sta[n]<=d)
>                                  ~~~~~~~~~
>         n++;
>     sta[n] = d;
>     sta[0] = 0;
>     for(i=1; i<=n; i++)
>     {
>         dis[i]=sta[i]-sta[i-1];
>         if(dis[i]>200 || (i==1||i==n)&&dis[i]>100 || n==1 && dis[i]>0)
>                                                     ~~~~~~~~~~~~~~~~~~~
>         {
>             cout<<"Impossible"<<endl;
>             return 0;
>         }
>         for(j=0; j<=200; j++)
>         {
>             f[i][j] = inf;
>         }
>     }
>     f[1][100-sta[1]] = 0;
>     for(i=1; i<n; i++)
>     {
>         for(j=0; j<=200; j++)
>         {
>             if(f[i][j]!=inf)
>             {
>                 for(k=0; k<=200-j; k++)
>                 {
>                     if(j+k>=dis[i+1] && f[i][j]+k*pri[i]<f[i+1][j+k-dis[i+1]])
>                     {
>                         f[i+1][j+k-dis[i+1]] = f[i][j]+k*pri[i];
>                     }
>                 }
>             }
>         }
>     }
>     cout<<f[n][100]<<endl;
>   //  printf("%d\n",f[n][100]);
>  //   cin.close();
>  //   cout.close();
>  //   fclose(stdin);
>  //   fclose(stdout);
>     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