|
常用链接
留言簿(1)
随笔分类
随笔档案
文章档案
收藏夹
搜索
最新评论
![](/images/xml.gif)
阅读排行榜
评论排行榜
Powered by: 博客园
模板提供:沪江博客
|
|
|
|
|
发新文章 |
|
|
#include <stdio.h>
#include <math.h>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
long n,k,ans=0;
long data[21];
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) /**///////////// int getans(long num) //判素数
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
long i;
long total;
total=(long)(sqrt(num));
for (i=2;i<=total;i++)
if (num%i==0) return 0;
ans++;
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
void dfs(long total,long num,long t) //深搜
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
long i;
if(total==k) getans(num);
else
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
for(i=t;i<=n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) {
num+=data[i];
dfs(total+1,num,i+1);
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) num-=data[i];/**////////////////你也可以看它这个, total表示?
//////////还踩×思父鍪?num表示取了这几个数的和,t表示从前t个数中取了total个数
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif) } /**//////////////////////////////
}
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif) ![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif) {
long i;
scanf("%ld%ld",&n,&k);
for(i=1;i<=n;i++) scanf("%ld",&data[i]);
dfs(0,0,1);
printf("%ld",ans);
return 0;
}
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
|
|