令x=0,得a0=n.令x=1,得a0+a1+a2+…数厅悄+an=2+22+23+…薯渣+2n= 2(1?2n) 1?2 =2n+1-2,an=1,由a1+a2+…+an-1+an=30-n,伏贺得2n+1-2-n=30-n,∴2n+1=32,解得n=4.故选C.