https://vjudge.net/problem/UVA-10970

题意:

把一个m行n列的矩形巧克力切成mn个1×1的方块,需要切几刀。

思路:

可以考虑用动态规划的方法去做,当然,最简单的是直接找到规律,直接计算出来。

 #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std; int n, m;
int d[][]; int dp(int i, int j)
{
int& ans = d[i][j];
if (ans != -) return ans;
if (i == ) return ans=j - ;
if (j == ) return ans=i - ;
if (i % == ) ans = * dp(i / , j) + ;
else if (j % == ) ans = * dp(i, j / ) + ;
else return ans = dp(i - , j) + j;
} int main()
{
ios::sync_with_stdio(false);
//freopen("D:\\txt.txt", "r", stdin);
while (cin >> n >> m)
{
memset(d, -, sizeof(d));
dp(n, m);
cout << d[n][m] << endl;
}
}
 #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std; int n, m; int main()
{
ios::sync_with_stdio(false);
//freopen("D:\\txt.txt", "r", stdin);
while (cin >> n >> m)
{
cout << m*n - << endl;
}
}

最新文章

  1. 使用Visual Studio SDK制作GLSL词法着色插件
  2. Docker命令学习
  3. 微信 {&quot;errcode&quot;:48001,&quot;errmsg&quot;:&quot;api unauthorized, hints: [ req_id: 1QoCla0699ns81 ]&quot;}
  4. [暴力搜索] POJ 3087 Shuffle&#39;m Up
  5. [2014.01.27]WFsoft.wfWebCtrl.wfPage 5.9
  6. Linux系统MySQL开启远程连接
  7. Hadoop 之Impala
  8. HTTP 错误 500.21 - Internal Server Error 处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler”
  9. 如何在TFS的过程模板中添加报表
  10. 基本Socket通信流程
  11. android 存储概念
  12. LA 3983 Robotruck
  13. 获取枚举Description的Name
  14. git推送本地分支到远端 以及删除远端分支的 命令
  15. vuex 模块
  16. HashMap和HashTable 学习
  17. 1.3 selenium IDE录制脚本转换为其他代码格式
  18. ionic2+Angular2:套接口明细步骤,以登录功能为例
  19. [转] babel 教程
  20. 【Python】print array时array中间是省略号没有输出全部的解决方法

热门文章

  1. MySQL IFNULL()函数用法MySQL
  2. 飞跃平野(sdut1124)
  3. 【Cocos2dx 3.3 Lua】剪裁结点ClippingNode
  4. [LeetCode] 429. N-ary Tree Level Order Traversal_ Easy
  5. [LeetCode] questions conclustion_Path in Tree
  6. gcc升级
  7. [转]autoid文件上传
  8. 页面点击,不是a标签也会刷新原因
  9. centos 网卡名称修改
  10. oracle中验证身份证是否合法的函数脚本