题意给你一个n*m的矩阵,从左上走到右下,走最短路,经过矩阵的点的值相乘,问能组成多少个6
思路这个和前一阵的cf的教育场的d题一样的,是一个有意思的迪屁,你要让这条路径有最多的2*3
1.一个状态f[i][j][k]表示i行j列,到这个点最多有k个3.一开始把所有的赋成-1,
f[i][j][k] = max(f[i - 1][j][k - a[i].p3] , f[i][j - 1][k - a[i].p3]);表示从左边或者上边转移过来的状态
2.每次转移的时候,你要看看,f[i - 1][j][k - a[i].p3] 是否等于-1,-1表示没有这种状态,转移不了,当不等于-1的时候才能转移。
3.第三维是3,不是2,因为3的话会是空间开的更小。
PS:补的时候,写成了memset(f , -1 , sizeof(-1));查了好久。。。。。。挂了好几发

 #include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>using namespace std;struct node{int p2 , p3;
}a[150][150];int f[120][120][2005];int main()
{int t;scanf("%d",&t);while(t--){int n , m;scanf("%d %d",&n ,&m);for(int i = 1 ; i <= n ; i++){for(int j = 1 ; j <= m ; j++){int x , tot = 0;scanf("%d",&x);while(x % 2 == 0) tot++ , x /= 2;a[i][j].p2 = tot;tot = 0;while(x % 3 == 0) tot++ , x /= 3;a[i][j].p3 = tot;}}memset(f , -1 , sizeof(f));for(int i = 1 ; i <= n ; i++) f[i][0][0] = 0;for(int i = 1 ; i <= m ; i++) f[0][i][0] = 0;for(int i = 1 ; i <= n ; i++){for(int j = 1 ; j <= m ; j++){for(int k = a[i][j].p3 ; k <= 2000 ; k++){if(f[i - 1][j][k - a[i][j].p3] != -1) f[i][j][k] = max(f[i][j][k] , f[i - 1][j][k - a[i][j].p3] + a[i][j].p2);if(f[i][j - 1][k - a[i][j].p3] != -1) f[i][j][k] = max(f[i][j][k] , f[i][j - 1][k - a[i][j].p3] + a[i][j].p2);}}}int Max = 0;for(int i = 0 ; i <= 2000 ; i++){Max = max(Max , min(i , f[n][m][i]));}printf("%d\n",Max);}
}

codeforces [Gym-100814E]相关推荐

  1. Codeforces Gym 101173 CERC 16 D BZOJ 4790 Dancing Disks

    Codeforces Gym 101173 CERC 16 D & BZOJ 4790 Dancing Disks 强烈安利这道构造题目,非常有意思. 这里用到的思想是归并排序! 多路归并排序 ...

  2. Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven)

    Codeforces Gym 101086 M ACPC Headquarters : AASTMT (Stairway to Heaven) 题目来源: Codeforces 题意: 给出一些比赛, ...

  3. [Codeforces Gym 101651/100725B] Banal Tickets

    Codeforces Gym 100725 题解: 先分两种情况, 积为000与积非0" role="presentation" style="position ...

  4. Codeforces Gym 100513G G. FacePalm Accounting 暴力

    G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...

  5. Codeforces Gym 100269 Dwarf Tower (最短路)

    题目连接: http://codeforces.com/gym/100269/attachments Description Little Vasya is playing a new game na ...

  6. Codeforces Gym 100676G Training Camp 状压dp

    http://codeforces.com/gym/100676 题目大意是告诉你要修n门课,每门课有一个权值w[i], 在第k天修该课程讲获得k*w[i]的学习点数,给出了课程与先修课程的关系,要修 ...

  7. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  8. Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset

    Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...

  9. Codeforces Gym 100650B Countdown (离线)

    题目链接:http://codeforces.com/gym/100650 根据给出的树和d,求出一些结点,这些结点形成子树的第d层结点数应该尽量多,具体要求可以参考题目. dfs一个结点前保存询问深 ...

  10. Codeforces Gym 101630J Travelling from Petersburg to Moscow (最短路)

    题目链接 http://codeforces.com/gym/101630/attachments 题解 zyb学长的题. 先枚举第\(k\)大的边权,设其边权为\(x\),然后把每条边边权减掉\(x ...

最新文章

  1. 刚刚,DeepMind被IJCAI授予杰出成就奖,因为他家把AlphaGo Zero做成了暖心的新垣结衣?
  2. js innerHTML 改变div内容的方法
  3. mete30是鸿蒙系统么,华为mete30pro什么时候能用上鸿蒙系统?
  4. numpy python 兼容_Python 2和3之间的numpy数组的不兼容性
  5. nginx配置http自动跳转https方案
  6. mysql递归查询树,帮你突破瓶颈
  7. paip.session的调试in php
  8. JavaScript表单验证
  9. 健康管理系统案列/APP/小程序/网站
  10. html 怎么做图标在圆圈上旋转,纯CSS3图标旋转效果
  11. 前端人不可错过的低代码神器,告别切图,一键成稿啦!
  12. 三方支付之支付宝支付实现逻辑
  13. node.js文件加密
  14. linux系统下ls -r命令的简单实现(C语言版)
  15. 河海大学计算机辅助,黄瑞
  16. 云效触发Jenkins自动构建
  17. 三大顶级Linux发行版对比
  18. 下载centos7.6光盘映像文件,使用VMware12创建虚拟机,设置固定IP,最全图文教程
  19. python操作数据库教程_python通用数据库操作工具 pydbclib|python基础教程|python入门|python教程...
  20. [科普]3.5mm耳机国标和美标

热门文章

  1. 如何在IOS上玩gba游戏(免越狱)
  2. VS2010 SP1发布及下载地址
  3. android常用布局详解
  4. JAVA爬虫--编写第一个网络爬虫程序
  5. 联想计算机无法启动怎么办,联想电脑打不开机怎么办
  6. Exchange2010安装配置
  7. NTP/PTP时间同步入门
  8. 专门查英语单词的软件_查英语单词的软件_有道翻译
  9. 疯狂java讲义 如何_[java学习]《疯狂java讲义》
  10. c语言实验报告模板电子版,c语言实验报告模板1.pdf