Codeforces Testing Round #14 (Unrated) B - Door Frames

用dp做的,当时没有细想,大概会有更简单的办法的。

#include 
#define min(_x,_y) ((_x<_y)?(_x):(_y))
using namespace std;
bool ok[10][10]={false};
int need[10][10]={0};
int main(){
    int length,r_l,up,i,j,k,l;
    cin>>length>>r_l>>up;
    for(i=0;i<=4;i++){for(j=0;j<=2;j++){
        if(i*r_l+j*up<=length)ok[i][j]=true;
        need[i][j]=100;
    }}
    need[0][0]=0;ok[0][0]=false;
    for(i=0;i<=4;i++){for(j=0;j<=2;j++){
        for(k=i;k>=0;k--){
            for(l=j;l>=0;l--){
                if(i-k>=0&&j-l>=0&&ok[k][l])need[i][j]=min(need[i][j],1+need[i-k][j-l]);
            }
        }
    }}
    printf("%d",need[4][2]);
}

你可能感兴趣的:(codeforces,动态规划)