題意:長度爲1,2,3,…,n的n根木棒,問至少偷走幾根木棒,才能使得剩下的木棒任意三根都無法組成三角形。
找規律,發現剩下的木棍爲斐波拉契數列。然後,n<=20打表就可以了。
代碼:
#include <stdio.h>
const int max_n=21;
int s[max_n]={0,0,0,0,1,1,2,3,3,4,5,6,7,7,8,9,10,11,12,13,14};
int main()
{
int t,n,i,p=1;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("Case #%d: %d\n",p++,s[n]);
}
return 0;
}