# 2320. Count Number of Ways to Place Houses ###### tags: `Leetcode` `Medium` `Dynamic Programming` Link: https://leetcode.com/problems/count-number-of-ways-to-place-houses/ ## 思路 count1代表截止到目前最后一个位置放建筑的方案总数 count2代表截止到目前最后一个位置不放建筑的方案总数 上一轮不管放不放建筑 这一轮都可以不放 但是只有上一轮不放建筑 这一轮才能放 ## Code ```java= class Solution { public int countHousePlacements(int n) { //1: last has house //2: last don't have house long count1=0, count2=1; int mod = 1000000007; for(int i=1; i<=n; i++){ long tempCount1 = count1; count1 = count2; //1 count2 = (tempCount1+count2)%mod;//1 } long ans = ((count1+count2)*(count1+count2))%mod; return (int)ans; } } ```