AcWing 3257. 跳一跳
原题链接
简单
作者:
no_one
,
2022-06-18 19:35:12
,
所有人可见
,
阅读 616
可能我的写法有点麻烦hh
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 40;
int a[N], f[N];
int idx;
int main()
{
while(1)
{
int x;
cin >> x;
if(x == 0) break;
else a[idx ++] = x;
}
for(int i = 0; i < idx; i ++)
{
if(a[i] == 1) f[i] = 1;
if(a[i] == 2 && a[i - 1] != 2) f[i] = 2;
if(a[i] == 2 && a[i - 1] == 2) f[i] = f[i - 1] + 2;
}
int res = 0;
for(int i = 0; i < idx; i ++) res += f[i];
cout << res << endl;
return 0;
}