题目大意:有长度为N的颜色段,共有m种颜色,要将其划分成若干段,每一段的费用为这一段的不同颜色的数目的平方。求最小总费用。
Sol:
首先我们注意到答案不超过n,因为我们显然可以将每一个划分为一段,答案为n.
于是每一段的颜色总数不超过sqrt(n).
因此我们维护最后出现的sqrt(n)种颜色最后出现的位置,进行转移。
总的时间复杂度为O(n*sqrt(n)).
Co...
分类:
其他好文 时间:
2014-09-22 10:59:52
阅读次数:
274
一。ReentrantLockpublic boolean tryLock()Acquires the lock only if it is not held by another thread at the time of invocation.Acquires the lock if it is...
分类:
其他好文 时间:
2014-09-22 03:46:51
阅读次数:
246
void lock()Acquires the lock.If the lock is not available then the current thread becomes disabled for thread scheduling purposes and lies dormant unt...
分类:
其他好文 时间:
2014-09-22 01:23:41
阅读次数:
417
A multiprocessing system having a plurality of processing nodes interconnected by an interconnect network. To optimize performance during spin-lock op...
分类:
移动开发 时间:
2014-09-22 00:56:21
阅读次数:
394
原文:5. SQL Server数据库性能监控 - 当前请求对于在线运行的系统,当前数据库性能监控,通常监视以下几点:
(1) 是否有阻塞 (Blocking);
(2) 是否有等待 (Waiting),阻塞就是锁 (Lock) 等待;
(3) 是否运行时间过长(Long running);
(4)...
分类:
数据库 时间:
2014-09-21 22:16:21
阅读次数:
314
本系列作为Java Performance:The Definitive Guide的读书笔记。
概览
在目前的JVM中,主要有4中垃圾回收器(Garbage Collector):
串行回收器(Serial Collector),主要用于单核计算机吞吐量(并行)回收器(Throughput/Parallel Collector)并发回收器(Concurrent/CMS Co...
分类:
编程语言 时间:
2014-09-21 18:47:50
阅读次数:
224
跟 column相关的常见的方法有:column_exists? (table_name, column_name, type = nil, options = {})add_column (table_name, column_name, type, options = {})remove_co....
分类:
其他好文 时间:
2014-09-21 18:38:31
阅读次数:
271
Condition的含义是条件变量,其实现依赖于系统,一般都要配合Mutex使用,使用步骤为:给mutex上锁(Lock),调用wait等待“条件”发生,如果没有发生则re-wait(),最后释放mutex(unlock),并继续执行。所有等待(wait)同一个“条件变量(condition)”的线...
分类:
移动开发 时间:
2014-09-21 18:37:51
阅读次数:
410
在System.Configuration命名空间下死活找不到ConfigurationManager类,运行程序便报错。遇到这样的情况,须要对项目加入引用。方法例如以下:右键references->add references->assemblies下的framework->勾选System.Co...
分类:
其他好文 时间:
2014-09-21 18:11:11
阅读次数:
188
constconst指针1 char greeting[] ="hello"; 2 char* p = greeting; // non-const pointer, non-const data3 const char* p = greeting; // non-const pointer, co...
分类:
编程语言 时间:
2014-09-21 16:45:40
阅读次数:
241