zoukankan      html  css  js  c++  java
  • hdu 4504(背包最优方案数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4504

    View Code
     1 /*
     2 #include<iostream>
     3 #include<cmath>
     4 using namespace std;
     5 int _count=0;
     6 
     7 void dfs(int a,int b,int count){
     8     if(count==0){
     9         if(a>b)_count++;
    10         return ;
    11     }else if((b-a)<count){
    12         _count+=pow(3.0,count);
    13         return ;
    14     }else {
    15         dfs(a+3,b,count-1);
    16         dfs(a+2,b,count-1);
    17         dfs(a+1,b,count-1);
    18     }
    19 }
    20 
    21 int main(){
    22     int a,b,time;
    23     while(~scanf("%d%d%d",&a,&b,&time)){
    24         _count=0;
    25         if(time<15&&a<=b){
    26             printf("0\n");
    27         }else {
    28             int count1=1+(time-15)/30;
    29             int count2=(time-15)/30;
    30             b+=count2;
    31             if(a+2*count1<b){
    32                 printf("0\n");
    33             }else if((b-a)<count1){
    34                 printf("%d\n",pow(3.0,count1));
    35             }else {
    36                 dfs(a,b,count1);
    37                 printf("%d\n",_count);
    38             }
    39         }
    40     }
    41     return 0;
    42 }
    43 */
    44 
    45 #include<iostream>
    46 #include<cstring>
    47 using namespace std;
    48 
    49 __int64 dp[24][77];//dp[i][j]表示第i次进攻后我方得分j(不算上原来的分数)时的最多方案数
    50 
    51 void Initiate(){
    52     memset(dp,0,sizeof(dp));
    53     //最多进攻20次,最多得分为60.
    54     dp[1][1]=dp[1][2]=dp[1][3]=1;
    55     for(int i=1;i<=20;i++){
    56         for(int j=1;j<=60;j++){
    57             if(j>1)dp[i][j]+=dp[i-1][j-1];
    58             if(j>2)dp[i][j]+=dp[i-1][j-2];
    59             if(j>3)dp[i][j]+=dp[i-1][j-3];
    60         }
    61     }
    62 }
    63 
    64 int main(){
    65     Initiate();
    66     int a,b,time;
    67     while(~scanf("%d%d%d",&a,&b,&time)){
    68         int count=time/15;
    69         int count1=(count+1)/2;
    70         int count2=count-count1;
    71         if(count1==0){
    72             if(a>b)printf("1\n");
    73             else printf("0\n");
    74             continue;
    75         }
    76         b+=count2;
    77         int tmp=(b-a)+1;
    78         if(tmp<0)tmp=0;
    79         __int64 ans=0;
    80         for(int i=tmp;i<=count1*3;i++){
    81             ans+=dp[count1][i];
    82         }
    83         printf("%I64d\n",ans);
    84     }
    85     return 0;
    86 }
  • 相关阅读:
    两小时入门Docker
    Django之Model操作
    Django-channels 实现WebSocket实例
    Python项目中的单元测试
    將Python打包成 exe可执行文件
    CORS 跨域
    购物车模块
    登陆模块
    Git 基本用法
    Django ORM性能优化 和 图片验证码
  • 原文地址:https://www.cnblogs.com/wally/p/2974776.html
Copyright © 2011-2022 走看看