• [LightOJ1017]Brush (III)(dp)


    题目链接:http://lightoj.com/volume_showproblem.php?problem=1017

    题意:给你一个无限大的平面(2D)上面有N个 点,一个宽w的刷子,最多使用k次,每次使用只能横着水平刷一次。问刷k次后刷过的地方最多可以覆盖多少个点。

    思路:其实读完题就知道这个题和x坐标没关系,我们只需要关心每一个点的y坐标就行了。可以动态规划,输入完后给每一个点的y坐标从小到大排序,定义dp(i,k)为前i个点刷了k次后最大能刷到的点数。转移的时候有两种情况,一种是之前刷了k次了,这里不刷,即dp(i-1,k);另一种是从大到小枚举j从(i~1),找到这个刷子能覆盖到的最大宽度,更新dp(i,k)=max(dp(i,k), dp(j-1,k-1)+cnt)即可。

      1 /*
      2 ━━━━━┒ギリギリ♂ eye!
      3 ┓┏┓┏┓┃キリキリ♂ mind!
      4 ┛┗┛┗┛┃\○/
      5 ┓┏┓┏┓┃ /
      6 ┛┗┛┗┛┃ノ)
      7 ┓┏┓┏┓┃
      8 ┛┗┛┗┛┃
      9 ┓┏┓┏┓┃
     10 ┛┗┛┗┛┃
     11 ┓┏┓┏┓┃
     12 ┛┗┛┗┛┃
     13 ┓┏┓┏┓┃
     14 ┃┃┃┃┃┃
     15 ┻┻┻┻┻┻
     16 */
     17 #include <algorithm>
     18 #include <iostream>
     19 #include <iomanip>
     20 #include <cstring>
     21 #include <climits>
     22 #include <complex>
     23 #include <fstream>
     24 #include <cassert>
     25 #include <cstdio>
     26 #include <bitset>
     27 #include <vector>
     28 #include <deque>
     29 #include <queue>
     30 #include <stack>
     31 #include <ctime>
     32 #include <set>
     33 #include <map>
     34 #include <cmath>
     35 using namespace std;
     36 #define fr first
     37 #define sc second
     38 #define cl clear
     39 #define BUG puts("here!!!")
     40 #define W(a) while(a--)
     41 #define pb(a) push_back(a)
     42 #define Rint(a) scanf("%d", &a)
     43 #define Rll(a) scanf("%lld", &a)
     44 #define Rs(a) scanf("%s", a)
     45 #define Cin(a) cin >> a
     46 #define FRead() freopen("in", "r", stdin)
     47 #define FWrite() freopen("out", "w", stdout)
     48 #define Rep(i, len) for(int i = 0; i < (len); i++)
     49 #define For(i, a, len) for(int i = (a); i < (len); i++)
     50 #define Cls(a) memset((a), 0, sizeof(a))
     51 #define Clr(a, x) memset((a), (x), sizeof(a))
     52 #define Full(a) memset((a), 0x7f7f, sizeof(a))
     53 #define lrt rt << 1
     54 #define rrt rt << 1 | 1
     55 #define pi 3.14159265359
     56 #define RT return
     57 #define lowbit(x) x & (-x)
     58 #define onenum(x) __builtin_popcount(x)
     59 typedef long long LL;
     60 typedef long double LD;
     61 typedef unsigned long long ULL;
     62 typedef pair<int, int> pii;
     63 typedef pair<string, int> psi;
     64 typedef pair<LL, LL> pll;
     65 typedef map<string, int> msi;
     66 typedef vector<int> vi;
     67 typedef vector<LL> vl;
     68 typedef vector<vl> vvl;
     69 typedef vector<bool> vb;
     70 
     71 const int maxn = 110;
     72 
     73 int n, K, w;
     74 int dp[maxn][maxn];
     75 int y[maxn];
     76 
     77 int main() {
     78     // FRead();
     79     int T, _ = 1, x;
     80     Rint(T);
     81     W(T) {
     82         Rint(n); Rint(w); Rint(K);
     83         For(i, 1, n+1) {
     84             Rint(x); Rint(y[i]);
     85         }
     86         sort(y+1, y+n+1);
     87         Cls(dp);
     88         For(i, 1, n+1) {
     89             For(k, 1, K+1) {
     90                 dp[i][k] = dp[i-1][k];
     91                 int cnt = 0;
     92                 for(int j = i; j >= 1; j--) {
     93                     if(y[i] - y[j] > w) break;
     94                     cnt++;
     95                     dp[i][k] = max(dp[i][k], dp[j-1][k-1]+cnt);
     96                 }
     97             }
     98         }
     99         int ret = -1;
    100         For(i, 1, K+1) ret = max(dp[n][i], ret);
    101         printf("Case %d: %d
    ", _++, ret);
    102     }    
    103     RT 0;
    104 }
  • 相关阅读:
    VM安装CentOs7虚拟机后无法上网之解决方法
    vue中touchEnd事件和touchStart、touchMove获取坐标不一样,IOS绑定touch事件失效
    【个推独家】让你一次性掌握Neo4j性能优化秘籍的三大狠招
    【深度干货】异构数据的SQL一站式解决方案
    个推基于Jenkins的自动打包构建实践
    个推CTO叶新江专访| 数据智能的未来,是不提大数据但其无所不在的时代
    应用系统间数据传输方式总结(附相关概念解释)
    JavaScript中“&&”和“||”操作符的意义,深入理解和使用场景
    静态布局、自适应布局、流式布局、响应式布局、弹性布局等的概念和区别
    前端跨域问题相关知识详解(原生js和jquery两种方法实现jsonp跨域)
  • 原文地址:https://www.cnblogs.com/kirai/p/5579252.html
Copyright © 2020-2023  润新知