代码

 #include <bits/stdc++.h>

 using namespace std;

 int cnt = ;

 void getNumVec(vector<int>& v, string s)
{
int temp = , flag = ;
for (int i = ;i < s.length(); ++i)
{
if (s[i] == ' ')
{
v.push_back(temp * flag);
temp = ;
flag = ;
}
else if (s[i] == '-')
{
flag = -;
}
else
{
temp *= ;
temp += s[i] - '';
}
}
v.push_back(temp * flag);
} bool check(vector<int> v)
{
int sz = v.size();
if (sz < )
{
return false;
} if (sz == )
{
return true;
} int d = v[] - v[];
for (int i = ; i < sz; ++i)
{
if (v[i] - v[i - ] != d)
{
return false;
}
}
return true;
} void dfs(vector<int>& v, vector<int>& temp, int start, int sz)
{
bool flag = false;
for (int i = start;i < sz; ++i)
{
temp.push_back(v[i]);
flag = check(temp);
if (flag || temp.size() < ) //剪枝
{
if (flag)
{
++cnt;
}
dfs(v, temp, i + , sz);
}
temp.pop_back();
}
} int main()
{
string s;
getline(cin, s); vector<int> v, temp;
getNumVec(v, s);
int sz = v.size();
dfs(v, temp, , sz); cout << cnt << endl; return ;
}
05-21 06:35