大家来讨论一下这道题目

ensoniq 2006-09-05 05:42:26
能解决的即结贴给分,计算限时2秒。这个题目来自gcj2006的练习题,不知道原来是哪一局用过的题目。google不厚道,出这样的练习题,还是250分的。 :)


Problem Statement
    
You want to send a group of salespeople from location 0 to location 1, but no two of them can travel through the same location (other than 0 and 1). This removes the possibility of trying to sell a customer the same product twice. Character j of element i (both 0-based) of adj denotes whether locations i and j are connected by a symmetric link ('1' for connected, '0' otherwise). Return the greatest number of salespeople that can be sent. The constraints will guarantee that locations 0 and 1 do not share a link.
Definition
    
Class:
SalesRouting
Method:
howMany
Parameters:
vector <string>
Returns:
int
Method signature:
int howMany(vector <string> adj)
(be sure your method is public)
    

Constraints
-
adj will contain between 3 and 12 elements, inclusive.
-
Each element of adj will contain exactly N characters, where N is the number of elements in adj.
-
Each character in adj will be '0' (zero) or '1' (one).
-
Character i of element j of adj will be the same as character j of element i.
-
Character i of element i of adj will be '0'.
-
Character 1 of element 0 of adj will be '0'.
Examples
0)

    
{
"001",
"001",
"110"
}
Returns: 1
We can send a single salesperson from location 0 to location 2, and finally to location 1.
1)

    
{
"0010",
"0010",
"1100",
"0000"
}
Returns: 1
Same as before, but now there is an isolated location 3.
2)

    
{
"001100",
"000001",
"100010",
"100010",
"001101",
"010010"
}
Returns: 1
The only location that is directly connected to location 1 is 5, so only 1 salesperson can be sent.
3)

    
{
"001111",
"001111",
"110000",
"110000",
"110000",
"110000"
}
Returns: 4

4)

    
{
"00000",
"00000",
"00000",
"00000",
"00000"
}
Returns: 0

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
...全文
552 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Michaelgs 2006-09-06
  • 打赏
  • 举报
回复
问题规模比较小, 我用的DP
f(n,set)表示从n点出发,经过set中的全部或部分点可以到达1的不相交路径的最大数目
f(n,set) = max{ f(i,set-{i}) }, adj[n][1] != 1 && adj[n][i] == 1
f(n,set) = f(0,set)+1, adj[n][1] == 1
phoenixinter 2006-09-05
  • 打赏
  • 举报
回复
network flow
pay attention that each vertex has a flow constraint
ensoniq 2006-09-05
  • 打赏
  • 举报
回复
网络流的话何解?brutal force?
galois_godel 2006-09-05
  • 打赏
  • 举报
回复
化点为线,就是网络流
ensoniq 2006-09-05
  • 打赏
  • 举报
回复
比网络流稍微简单些,我的理解是一个节点一旦访问过就再不能再访问,因为不能重复推销。
galois_godel 2006-09-05
  • 打赏
  • 举报
回复
这不就是网络流嘛
内容概要:本文系统梳理了多个科研领域的前沿研究与技术实现,重点涵盖FDTD方法中的完美匹配层(PML)研究,以及Matlab/Simulink在电磁、电力、控制、通信、信号处理、图像处理、路径规划、能源系统优化等领域的仿真与算法实现。文中列举了大量基于Matlab和Python的科研案例,如风电功率预测、负荷预测、无人机三维路径规划、电池系统故障诊断、雷达模拟、通信编码、微电网优化调度等,并强调结合智能优化算法(如粒子群、遗传算法、深度学习等)提升系统性能。同时,提供了丰富的代码资源与仿真模型,涵盖永磁同步电机控制、逆变器设计、多智能体任务分配、虚拟电厂调度等复杂系统,助力科研人员快速开展复现实验与创新研究。; 适合人群:具备一定编程基础,熟悉Matlab/Python工具,从事电气工程、自动化、通信、人工智能、新能源、控制科学等相关领域研究的研发人员及研究生。; 使用场景及目标:① 学习并实现FDTD仿真中的PML边界条件以有效抑制数值反射;② 掌握Matlab/Simulink在多物理场建模、控制系统设计与优化算法中的综合应用;③ 借助提供的代码资源完成科研复现、课程设计、竞赛项目或工程原型开发; 阅读建议:此资源以科研实战为导向,不仅提供理论方法,更强调代码实现与仿真验证。建议读者结合自身研究方向,按目录顺序查阅相关模块,下载配套代码进行调试与二次开发,以达到学以致用、融会贯通的目的。

33,026

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧