fork download
  1. import java.util.Scanner;
  2.  
  3. /**
  4.  * Created by Shreyans Sheth [bholagabbar] on 10/14/2015 at 7:23 PM using IntelliJ IDEA (Fast IO Template)
  5.  */
  6.  
  7. class solve
  8. {
  9. public static void main(String[] args) throws Exception
  10. {
  11. //System.setIn(new FileInputStream("E:/Shreyans/Documents/QBIT_2015/src/Q05/input.txt"));
  12. Scanner sc=new Scanner(System.in);
  13. int MOD=(int)(1e9)+7;
  14. int t=sc.nextInt();
  15. while(t-->0)
  16. {
  17. int n=sc.nextInt();
  18. int k=sc.nextInt();
  19. int[] dp=new int[n+1];
  20. for(int i=1;i<n;i++)
  21. dp[i]=1;//No 'k' consecutive reds possible. Only blue
  22. dp[k]=2;//Here 2 possible. k red and k blue
  23. for(int i=k+1;i<=n;i++)
  24. dp[i]=(dp[i-1]%MOD+dp[i-k]%MOD)%MOD;//Work out dp condition
  25. System.out.println(dp[n]);
  26. }
  27. }
  28. }
Success #stdin #stdout 0.14s 321344KB
stdin
1
4
2
stdout
5