解题思路:
与一楼的思路一致,但因为用set会超时,所以采用了以下方法优化
参考代码:
#include<bits/stdc++.h>
using namespace std;
int n;
int g[100005],cut=0,ans;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
int w;
cin>>w;
cut++;
if(g[w]==0) g[w]=cut;
for(int j=1;j<100005;j++){
if(g[j]>0&&g[j]<cut){
if(g[j+w]==0) g[j+w]=cut;
if(g[abs(j-w)]==0) g[abs(j-w)]=cut;
}
}
}
for(int j=1;j<100005;j++){
if(g[j]>0) ans++;
}
cout<<ans;
return 0;
}
0.0分
0 人评分
The 3n + 1 problem (C语言代码)浏览:714 |
十->二进制转换 (C语言代码)浏览:1395 |
十->二进制转换 (C++代码)(零和负数需要特殊处理)浏览:1040 |
点我有惊喜!你懂得!浏览:2212 |
C语言训练-谁家孩子跑最慢* (C语言代码)浏览:1507 |
C语言训练-排序问题<1> (C语言代码)浏览:1348 |
C语言训练-角谷猜想 (C语言代码)浏览:1705 |
C语言程序设计教程(第三版)课后习题6.2 (C语言代码)浏览:685 |
C语言考试练习题_保留字母 (C语言代码)浏览:700 |
单词个数统计 (C语言代码)浏览:1009 |