- 1、本文档共34页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
ACM程序设计之DP
ACM程序设计 东北林业大学 陈宇 Lg_chenyu@ 今天你AC 了吗? 第7讲 DP(二) 我校的ACM在线评测系统 课件下载地址: /kj/acm06.ppt Function Run Funnefu16 We all love recursion! Dont we? Consider a three-parameter recursive function w(a, b, c): if a = 0 or b = 0 or c = 0, then w(a, b, c) returns: 1 if a 20 or b 20 or c 20, then w(a, b, c) returns: w(20, 20, 20) if a b and b c, then w(a, b, c) returns: w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c) otherwise it returns: w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1) This is an easy function to implement. The problem is, if implemented directly, for moderate values of a, b and c (for example, a = 15, b = 15, c = 15), the program takes hours to run because of the massive recursion. input The input for your program will be a series of integer triples, one per line, until the end-of-file flag of -1 -1 -1. Using the above technique, you are to calculate w(a, b, c) efficiently and print the result. output Print the value for w(a,b,c) for each triple. sample_input 1 1 1 2 2 2 10 4 6 50 50 50 -1 7 18 -1 -1 -1 思路:递归好 long long data[21][21][21]; long long inf(int x,int y,int z) { if (x=0||y=0||z=0) return 1; if (x20||y20||z20) return inf(20,20,20); if (xyyz) { if (data[x][y][z]==-1) data[x][y][z]=inf(x,y,z-1)+inf(x,y-1,z-1)-inf(x,y-1,z); return data[x][y][z]; } else { if (data[x][y][z]==-1) {data[x][y][z]=inf(x-1,y,z)+inf(x-1,y-1,z)+inf(x-1,y,z-1)-inf(x-1,y-1,z-1); } return data[x][y][z]; } } main()函数 int main(int argc, char *argv[]) { int x,y,z; while(cinxyz) { if (x==-1y==-1z==-1) break; memset(data,-1,sizeof(data)); coutw(x, y, z) = inf(x,y,z)endl; } //system(PAUSE); return EXIT_SUCCESS; } Recaman Sequence nefu91 The Recamans sequence is defined by a0 = 0 ; for m 0, am = am?1 ? m if the rsulting am is positive and not already in
您可能关注的文档
- afb_某咨询公司做的薪酬方案与绩效考核体系 ppt课件.ppt
- amj_0104_广州某物业管理公司岗位职责.doc
- 肝炎病毒的检测方法和防治措施.pptx
- 2024年事业单位教师招聘(言语理解与表达)300题附参考答案(b卷).pdf
- 浅谈如何做好学困生的转化工作.doc
- 新北师大版八年级数学下册知识点总结 .pdf
- 新北师大版三年级数学下册全册反思 .pdf
- 浅谈如何做好中学篮球队教练员的对策.doc
- 浅谈如何做好电视新闻素材收集工作.docx
- 2024年膜分离制氮设备项目申请报告范文.docx
- 专题06 全面依法治国-2020-2024年五年高考1年模拟政治真题分类汇编(北京专用)(原卷版).docx
- 专题06 全面依法治国-2020-2024年五年高考1年模拟政治真题分类汇编(北京专用)(解析版).docx
- 新人教版英语七年级上册全册教案(Go_For_It) .pdf
- 新媒体笔试试题 .pdf
- 新媒体概论教学大纲与实训大纲 .pdf
- 2020-2024年五年高考1年模拟生物真题分类汇编(山东专用) 专题18 基因工程(解析版).docx
- 2020-2024年五年高考1年模拟生物真题分类汇编(山东专用) 专题18 基因工程(原卷版).docx
- 2020-2024年五年高考生物真题分类汇编(全国版)专题01 组成细胞的分子(解析版).docx
- 2020-2024年五年高考生物真题分类汇编(全国版)专题01 组成细胞的分子(原卷版).docx
- 浅谈如何上好高三物理试卷讲评课.doc
文档评论(0)