• 百度之星2017资格赛1003 度度熊与邪恶大魔王


    思路:

    真是菜的不行。

    实现:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 const int INF = 0x3f3f3f3f;
     7 int dp[11][1001], A[100005], B[100005], K[1005], P[1005], n, m; 
     8 
     9 int main()
    10 {
    11     while (scanf("%d %d", &n, &m) != EOF)
    12     {
    13         for (int i = 0; i < n; i++) scanf("%d %d", &A[i], &B[i]);
    14         for (int i = 0; i < m; i++) scanf("%d %d", &K[i], &P[i]);
    15         memset(dp, 0x3f, sizeof dp);
    16         for (int j = 0; j <= 10; j++)
    17         {
    18             dp[j][0] = 0;
    19             for (int i = 0; i < m; i++)
    20             {
    21                 if (P[i] > j)
    22                 {
    23                     for (int k = 1; k <= 1000; k++)
    24                     {
    25                         dp[j][k] = min(dp[j][k], K[i] * ((k + P[i] - j - 1) / (P[i] - j)));
    26                     }
    27                 }
    28             }
    29         }
    30         
    31         for (int j = 0; j <= 10; j++)
    32         {
    33             for (int i = 1; i < m; i++)
    34             {
    35                 for (int k = 1; k <= 1000; k++)
    36                 {
    37                     if (P[i] > j && k - (P[i] - j) >= 0)
    38                     {
    39                         dp[j][k] = min(dp[j][k], dp[j][k - (P[i] - j)] + K[i]);
    40                     }
    41                 }
    42             }
    43         }
    44         
    45         long long sum = 0;
    46         bool flg = true;
    47         for (int i = 0; i < n; i++)
    48         {
    49             if (dp[B[i]][A[i]] >= INF)
    50             {
    51                 flg = false; break;
    52             }
    53             sum += (long long)dp[B[i]][A[i]];
    54         }
    55         if (!flg) puts("-1");
    56         else printf("%I64d
    ", sum);
    57     }
    58     return 0;
    59 }
  • 相关阅读:
    函数
    vue中v-for循环如何将变量带入class的属性名中
    代码规范 前端导航
    2019.8.5 mysql 删除 更新
    2019.8.1
    2019.7.31 Xshell简单学习
    日常使用知识点
    FormData实现文件多次添加累加上传和选择删除
    上传图片
    验证码
  • 原文地址:https://www.cnblogs.com/wangyiming/p/7296509.html
Copyright © 2020-2023  润新知