Word Construction
来源:互联网 发布:淘宝网天猫商城女装 编辑:程序博客网 时间:2024/06/05 03:06
题目1 : Word Construction
- 样例输入
8the be to of and a in that
- 样例输出
4
描述
Given N words from the top 100 common words in English (see below for reference), select as many words as possible as long as no two words share common letters.
Assume that the top 100 common words in English are:
the be to of and a in that have i it for not on with he as you do at this but his by from they we say her she or an will my one all would there their what so up out if about who get which go me when make can like time no just him know take people into year your good some could them see other than then now look only come its over think also back after use two how our work first well even new want because any these give day most us
输入
The first line contains an integer N, denoting the number of words. (1 ≤ N ≤ 40)
The second line contains N words from the top 100 common words.
输出
Output the most number of words can be selected.
https://www.coursera.org/learn/algorithms/lecture/pTihC/072zui-da-tuan-wen-ti
http://blog.csdn.net/whosemario/article/details/8513836
import java.util.Arrays;import java.util.Scanner;/* * 求最大独立集 * 转为求补图的最大团 */public class Main {static int bound = -1;public static void main(String[] args) {Scanner sc = new Scanner(System.in);int n = sc.nextInt();String[] ss = new String[n];for(int i=0; i<n; i++) ss[i] = sc.next();boolean[][] adj = new boolean[n][n];for(int i=0; i<n; i++)Arrays.fill(adj[i], true);for(int i=0; i<n; i++)for(int j=i; j<n; j++)for(char c: ss[j].toCharArray())if(ss[i].indexOf(c) != -1){adj[i][j] = false;adj[j][i] = false;}boolean[] use = new boolean[n];dfs(adj, n, 0, use, 0);System.out.println(bound);}private static void dfs(boolean[][] adj, int n, int s, boolean[] use, int cnt) {bound = Math.max(bound, cnt);if(s == n)return;if(cnt + n-s <= bound)return;boolean canAdd = true;for(int i=0; i<s; i++) {if(use[i] && !adj[i][s]) {canAdd =false;break;}}if(canAdd) {use[s] = true;dfs(adj, n, s+1, use, cnt+1);use[s] = false;}dfs(adj, n, s+1, use, cnt);}}
- Word Construction
- Word Construction hiho一下第170周
- Managing Construction
- Tree Construction
- Road Construction
- Under Construction
- multiviews construction
- uva10720Graph Construction
- construction equipme
- default construction
- hdu3516Tree Construction
- Elegant Construction
- Construction method
- Object-Oriented Software Construction
- PostScript中的Path Construction
- Object-Oriented Construction Handbook
- Agile Software Construction
- Agile Software Construction
- Android模拟器Genymotion安装使用教程详解
- jQuery 事件
- 1499 图
- c#获取屏幕上某坐标点的颜色
- java获取屏幕上某坐标点的颜色
- Word Construction
- Vue实现简单ToDoList
- java获取屏幕截图
- c#获取屏幕截图
- C语言-函数指针例子-process
- 一点一点理清思路
- Android 中IPC实践
- 每日掌握一个Linux命令 之 字符操作命令 tr
- MySQL的数据库存储引擎--MyISAM和InnoDB