• bzoj 1042: [HAOI2008]硬币购物


    网上题解一搜一大把我就不献丑了,直接放代码吧

     1 #include <cstdio>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <iostream>
     5 using namespace std;
     6 #define N 100008
     7 #define M 1008
     8 
     9 long long  S,F[N],n,C[5],T,A[M][5];
    10 
    11 void init()
    12 {
    13     for (int i = 1;i <= 4;i++) scanf("%d",&C[i]);
    14     F[0] = 1;
    15     scanf("%lld",&T);
    16     for (int i = 1;i <= T;i++) 
    17     {
    18         for (int j = 1;j <= 4;j++) scanf("%d",&A[i][j]);
    19         scanf("%lld",&A[i][0]);
    20         S = max(S,A[i][0]);
    21     }
    22 }
    23 
    24 void DP()
    25 {
    26     for (int i = 1;i <= 4;i++)
    27         for (int j = 0;j <= S;j++)
    28             if (C[i]+j <= S) F[C[i]+j] += F[j]; 
    29 }
    30 
    31 void work()
    32 {
    33     for (int i = 1;i <= T;i++)
    34     {
    35         long long ans = 0;
    36         long long  S = A[i][0];
    37         ans += F[S];
    38         for (int j = 1;j <= 4;j++) 
    39         if (S - (A[i][j]+1)*C[j] >= 0)
    40         {
    41             ans -= F[S - (A[i][j]+1)*C[j]];
    42             for (int k = j+1;k <= 4;k++) 
    43             if (S - (A[i][j]+1)*C[j] - (A[i][k]+1)*C[k] >= 0)
    44             {
    45                 ans += F[S - (A[i][j]+1)*C[j] - (A[i][k]+1)*C[k]];
    46                 for (int l = k+1;l <= 4;l++)
    47                 if (S - (A[i][j]+1)*C[j] - (A[i][k]+1)*C[k] - (A[i][l]+1)*C[l] >= 0)
    48                 {
    49                     ans -= F[S - (A[i][j]+1)*C[j] - (A[i][k]+1)*C[k] - (A[i][l]+1)*C[l]];
    50                     for (int m = l+1;m <= 4;m++)
    51                     if (S - (A[i][j]+1)*C[j] - (A[i][k]+1)*C[k] - (A[i][l]+1)*C[l] - (A[i][m]+1)*C[m] >= 0)
    52                         ans +=F[S - A[i][j]+1*C[j] - (A[i][k]+1)*C[k] - (A[i][l]+1)*C[l] - (A[i][m]+1)*C[m]]; 
    53                 }
    54             }
    55         }
    56         printf("%lld
    ",ans);
    57     }
    58 
    59 }
    60 
    61 int main()
    62 {
    63     init();
    64     DP();
    65     work();
    66     return 0;
    67 }
    View Code
  • 相关阅读:
    H5C3综合案例
    CSS3 3D转换
    CSS3 动画
    CSS3 2D转换
    html+css入门基础案例之页面设计
    0tcpdump使用与ping
    redis计划(yet)
    为什么hashmap以2的倍数作为桶的长度,同时以2作为扩容倍数
    maven SNAPSHOT
    maven dependengcy:tree 查看maven依赖树(母项目指定pluginManagement)
  • 原文地址:https://www.cnblogs.com/wulala979/p/3537035.html
Copyright © 2020-2023  润新知