`
king_tt
  • 浏览: 2114109 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

uva 11552 - Fewest Flops ( 多维dp )

 
阅读更多


本文出自 http://blog.csdn.net/shuangde800



题目点击打开链接


题意

给一个字符串,把它分为k块,例如字符串“helloworld”分成2块,"hello", "world"

每一块里面的字母可以任意的排序。

最终字符串, 连续的一样的字母算作一个chunk,问总chunks最少是多少?



思路

f[i][j]: 第i块的第j位排在最后一位的最少chunks


对于每个单独的一块,它的chunks就是等于出现的不同字母数

第i块的chunks记做 chunks[i]


如果第i-1块的最后一位和第i块的第一位是一样的,那么可以合并这两个,总chunks可以减少一个


f[i][j] = min{ 如果i-1块的第k位和i块的第一位不同: f[i-1][k]+chunks[i],
如果i-1块的第k位和i块的第一位相同: f[i-1][k]+chunks[i]-1 }


代码

<script src="https://code.csdn.net/snippets/544.js" type="text/javascript"></script>


分享到:
评论

相关推荐

    poj 3260 The Fewest Coins.md

    poj 3260 The Fewest Coins.md

    ST7539-G4_V1.2.pdf

    ST7539 is a driver & controller LSI for graphic dot-matrix liquid crystal display systems. It contains 192-segment and 64-common with 1-icon-common driver ...display system with the fewest components.

    ST7687驱动程序

    The ST7687S is a driver & controller LSI for 65K color graphic dot-matrix ...power supply circuits necessary to drive liquid crystal, it is possible to make a display system with the fewest components.

    Python GUI Programming Cookbook(PACKT,2015)

    This book uses the simplest programming style, using the fewest lines of code to create a GUI in Python, and then advances to using object-oriented programming in later chapters. If you are new to ...

    Python GUI Programming Cookbook.pdf

    This book uses the simplest programming style, using the fewest lines of code to create a GUI in Python, and then advances to using object-oriented programming in later chapters. If you are new to ...

    Python GUI Programming Cookbook

    This book uses the simplest programming style, using the fewest lines of code to create a GUI in Python, and then advances to using object-oriented programming in later chapters. If you are new to ...

    ADM-Queryer

    Find the party that received fewest votes in a given constituency.Q2. Find the list of constituencies in which both a Labour candidate (“lab”) and an Ecology candidate (“eco”) stood plus the tota

    Mtree – Tree Creation v2.5.2

    • Control the polygon count, get the most out of the fewest triangles. • Create Branches textures from a single leaf texture with the Branch Editor. • Save your finished tree as a prefab that is ...

    用最少的代码,快速训练并调用一个机器学习图像分类模型.zip

    Quickly train and build a machine learning image classification model with a fewest lines of code. 用最少的代码,快速训练并调用一个机器学习图像分类模型

    A calculating method for the

    A calculating method for the fewest cutting passes on sapphire substrate at a certain depth using specific down force energy with an AFM probe

    greedy algorithm

    A familiar scenario is the change-making problem that we often encounter at a cash register: receiving the fewest numbers of coins to make change after paying the bill for a purchase. For example, ...

Global site tag (gtag.js) - Google Analytics