List All Of The Subsets

本文介绍了一种生成全集子集的算法,通过回溯法构建子集树,利用二进制位表示元素是否存在子集中,实现高效生成所有可能的子集。

Problem description:Please list all of the subsets of a known set including the empty set.

My idea: one thinking of the algorithm backtracking is to generate a tree of subset and the condition of an element in the super set for a subset is either on or off.Hence we can specialize the subset tree to a binary tree and we print once when we reach the bottom of the tree each time.It is also easy to write a program.
 
复制代码
 1 #include <stdio.h>
 2  #define MAX 1000
 3  
 4  int n=3;  //the number of the set elements
 5  int set[MAX]={1,2,3};
 6  int count=0;//the number of the subset.
 7  
 8  void DFS(int level);
 9  void print_set();
10  
11  int main()
12  {
13      DFS(0);
14      return 0;
15  }
16  
17  void DFS(int level)
18  {
19      if(level==n)
20      {
21          print_set();
22          return ;
23      }
24      int save=set[level];
25      set[level]=0;
26      int index=0;
27      for(index=0;index<2;index++)
28      {
29          DFS(level+1);
30          set[level]=save;
31      }
32  
33  }
34  
35  void print_set()
36  {
37      int index;
38      count++;
39      printf("%d: {",count);
40      for(index=0;index<n;index++)
41      {
42          if(set[index]!=0) 
43              printf("%d ",set[index]);
44      }
45      printf("}\n");
46  }
复制代码

 

Visualizing Regression analyses In this practical, you will write script that draws and saves a pdf file of the following figure, and writes the accompanying regression results to a formatted table in csv. Note that as the plot suggests, that the analysis must be subsetted by the Predator.lifestage field of the dataset. image Write a script that generates this figure Guidelines: Write a R script file called PP_Regress.R and save it in the Code directory. Sourcing or running this script should result in one pdf file containing the following figure being saved in the results directory: (Hint: Use the print() command to write to the pdf) In addition, the script should calculate the regression results corresponding to the lines fitted in the figure and save it to a csv delimited table called (PP_Regress_Results.csv), in the results directory. (Hint: you will have to initialize a new dataframe in the script to first store the calculations and then write.csv() or write.table() it.) All that you are being asked for here is results of an analysis of Linear regression on subsets of the data corresponding to available Feeding Type Predator life Stage combination — not a multivariate linear model with these two as separate covariates! The regression results should include the following with appropriate headers (e.g., slope, intercept, etc, in each Feeding type life stage category): regression slope, regression intercept, R , F-statistic value, and p-value of the overall regression (Hint: Review the Stats week!). The script should be self-sufficient and not need any external inputs — it should import the above predator-prey dataset from the appropriate directory, and save the graphic plots to the appropriate directory (Hint: use relative paths). Anybody should be able to source it without errors. You can also use the dplyr function instead of looping (see R Chapter, and the ggplot command instead of qplot. 目标输出是如图 然后这个是任务 帮我讲解并且给我代码完成这个任务
11-01
The team Test just finished an exciting JB/ICPC competition. They are eager to know their ranking, but the board has been closed. So they can only guess their ranking by observing the submissions of other teams. Now let’s briefly introduce the rules of ranking. Each team has two statistics: the number of solved problems and penalty time. All teams are ranked according to their numbers of solved problems. If the numbers of solved problems of two different teams are equal, then they are ranked according to the penalty time. Each time a team passes a problem, the number of solved problems +1, and the time (in minutes) elapsed from the beginning of the competition is added to their penalty time. If a team has multiple submissions, each of the failed submissions will result in a 20 added to their penalty time. At the time when the competition lasts for four hours, the board will stop updating. In other words, the board is "frozen". After that, you can only see the submission status of other teams (the number of attempts, the time of the last submission), but you cannot see whether those submissions are accepted or not. In addition, the competition lasts for five hours in total. In particular, all teams will not submit solutions to the problem after getting an "Accepted". If two teams have the same number of solved problems and penalty time, then they are ranked the same. Please help the team Test guess the highest and lowest rankings they can reach based on the current board. The input contains several test cases, and the first line contains a positive integer indicating the number of test cases, . For each test case, the first line is a positive integer indicating the number of other teams, where . Then for each team, the first line are two integers and , where indicating the number of solved problems and indicating the penalty time of this team. The second line contains an integer indicating the submissions of problems of this team after the board is frozen. Then following lines, each line contains two positive integers and indicating the time of the last submission and the submit times of a problem of this team. Finally there is one line contains two integers and indicating the number of solved problems and the penalty time of the team Test. For each test case, output a line containing two positive integers indicating the highest and lowest rankings of the team Test. 输入样例 1 1 1 30 1 250 2 1 20 输出样例 1 2
最新发布
12-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值