分析:把」已經使用過的火柴數i」看成狀態,可以得到乙個圖。從前往後每新增乙個數字x,就從狀態i轉移到i+c[x],其中c[x]代表數字x需要的火柴數。當i=0的時候不允許
使用數字0(最後當n>=6時,給答案單獨加上1,代表整數0)。
令d(i)為從結點0到結點i的路徑條數,則答案f(n)=d(1)+d(2)+d(3)+...+d(n)(因為火柴不必用完,所以使用的火柴的數目可能是1,2,3,...,n)。
程式實現時,我們可以按照從小到大的順序用d(i)更新所有的d(i+c[j])(j取遍數字0~9),
這道題思路難度是狀態轉移,而編碼難度在大數加法,好久沒寫大數加法,又有些生疏了,貼上**:
#include#include#include#include#includeusing namespace std;
#define ll long long
const int maxn=505;
const int n=2005;
struct bign
bign (int number)
void delzero()
if(len==0)
num[len++]=0;
}void put()
bign (int number)
bign (const char* number)
void delzero ();
void put ();
void operator = (int number);
void operator = (char* number);
bool operator < (const bign& b) const;
bool operator > (const bign& b) const
bool operator <= (const bign& b) const
bool operator >= (const bign& b) const
bool operator != (const bign& b) const
bool operator == (const bign& b) const
void operator ++ ();
void operator -- ();
bign operator + (const int& b);
bign operator + (const bign& b);
bign operator - (const int& b);
bign operator - (const bign& b);
bign operator * (const int& b);
bign operator * (const bign& b);
bign operator / (const int& b);
//bign operator / (const bign& b);
int operator % (const int& b);
};/*code*/
const int n = 2005;
const int c[20] = ;
bign dp[n];
int main ()
}dp[6] = dp[6] + 1;
for (int i = 2; i <= 2000; i++)
dp[i] = dp[i] + dp[i-1];
int n;
while (scanf("%d", &n) == 1 && n > 0)
return 0;
}void bign::delzero ()
}void bign::put ()
void bign::operator = (char* number)
void bign::operator = (int number)
delzero ();
}bool bign::operator < (const bign& b) const
void bign::operator ++ ()
while (s)
}void bign::operator -- ()
delzero ();
}bign bign::operator + (const int& b)
bign bign::operator + (const bign& b)
while (bignsum)
return ans;
}bign bign::operator - (const int& b)
bign bign::operator - (const bign& b)
ans.delzero ();
return ans;
}bign bign::operator * (const int& b)
while (bignsum)
return ans;
}bign bign::operator * (const bign& b)
ans.len = i + b.len;
while (bignsum)
} return ans;
}bign bign::operator / (const int& b)
ans.len = len;
ans.delzero ();
return ans;
}int bign::operator % (const int& b)
return s;
}
1137 矩陣乘法
1137 矩陣乘法 基準時間限制 1 秒 空間限制 131072 kb 分值 0 難度 基礎題 給出2個n n的矩陣m1和m2,輸出2個矩陣相乘後的結果。input 第1行 1個數n,表示矩陣的大小 2 n 100 第2 n 1行,每行n個數,對應m1的1行 0 m1 i 1000 第n 2 2n ...
Wikioi P1137 計算係數
題目描述 description 給定乙個多項式 ax by k,請求出多項式展開後x n y m項的係數。輸入描述 input description 共一行,包含 5 個整數,分別為a,b,k,n,m,每兩個整數之間用乙個空格隔開。輸出描述 output description 輸出共 1 行,...
CODEVS 1137 計算係數
題目描述 description 給定乙個多項式 ax by k,請求出多項式展開後x n y m項的係數。輸入描述 input description 共一行,包含 5 個整數,分別為a,b,k,n,m,每兩個整數之間用乙個空格隔開。輸出描述 output description 輸出共 1 行,...