Time Exceeded
foo.c: In function 'main': foo.c:12:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^~~~~~~~~~~~~~~
[Hydro](https://hydro.ac)提供评测服务
代码
#include <stdio.h>
int dp[3] = {0}; // 因为到达当前台阶的走法只与前面2个台阶的走法有关
int main(int argc, char const *argv[])
{
dp[0] = 1;
dp[1] = 2;
int n;
int temp;
scanf("%d", &n);
while (n -- > 2){
temp = dp[0] + dp[1];
dp[2] = temp > 1e9+7 ? temp % (int) (1e9+7) : temp;
dp[0] = dp[1];
dp[1] = dp[2];
}
printf("%d", dp[2]);
return 0;
}